Mapping Array of Arrays that have mapped fields?

I want to map a field to store data like so
field1:[ [ {val:1}, {val:2} ], [ {val:3} ], [ {val:4} ] ]

For the life of me I can't find how to map all the way down to "val:number"
Thank you for any help even its just saying it is or isn't possible.

Elasticsearch does not have a specialistic array type: any field accepts 0 or more values. The mapping of your document could simply be:

PUT my_index
{
  "mappings": {
    "properties": {
      "field1": {
        "properties": {
          "val": {
            "type": "integer"
          }
        }
      }
    }
  }
}

It's good to point out here that Elasticsearch will flatten your document. In your example, indexing the following document would have the same result:

{
  "field1": {
    "val": [
      1,
      2,
      3,
      4
    ]
  }
}

If you want to index arrays of objects, and really treat them as separate objects, you may want to consider using nested types instead. Check the docs for an explanation. Your mapping would become:

PUT my_index
{
  "mappings": {
    "properties": {
      "field1": {
        "type": "nested",
        "properties": {
          "val": {
            "type": "integer"
          }
        }
      }
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.