SOufiane Fadil
SOufiane Fadil

Reputation: 163

ElasticSearch field with different types in one single index

We have a scenario in a service that accepts multiple types of data and we want to store in ElasticSearch so we can benefit from its search capabilities.

Data could be a String, Number, Object or an Array of objects as the following:

POST my-index/_doc/1
{
  "additionalData": [
    {
      "values": {
        "some-field": "some-value",
        "some-other-field": "some-value"
      }
    }
  ]
}

POST my-index/_doc/1
{
  "additionalData": [
    {
      "values": [12345, 9875]
    }
  ]
}

POST my-index/_doc/1
{
  "additionalData": [
    {
      "values": "Some text"
    }
  ]
}

Is there a way to store that in elasticSearch? or better to store in other NoSQL Databases like Mongodb?

PS: we are using Es 7.x, and would like to keep using ES.

Upvotes: 0

Views: 20

Answers (1)

Val
Val

Reputation: 217304

If you don't need to search on those values, it's possible with a disabled field (i.e. not indexed, not stored)

However, if you want to search on those value, it's not possible. Each field must have a specific type (object, numeric, text, etc) and then you can only store values of that type in the field.

Upvotes: 1

Related Questions