Query Nested Array

I have an object that I want to index into an Elasticsearch index. Some of the fields inside the object have a nested array of JSON objects inside them. For example:

"history":[
		{"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}},
		{"color":"b","from":"e7","to":"e5","flags":"b","piece":"p","san":"e5","ts":{"$numberLong":"1586861527710"}},
		{"color":"w","from":"f2","to":"f4","flags":"b","piece":"p","san":"f4","ts":{"$numberLong":"1586861531620"}},
		{"color":"b","from":"d8","to":"h4","flags":"n","piece":"q","san":"Qh4#","ts":{"$numberLong":"1586861533363"}}
		],

The mapping i have used for this field is:

{
  "mappings": {
    "properties": {
      "history" : {
        "type" : "nested",
        "properties": {
          "color": {"type" : "keyword"},
          "from" : {"type" : "keyword"},
          "to" : {"type" : "keyword"},
          "flags" : {"type" : "keyword"},
          "san" : {"type" : "keyword"},
          "ts" : {
            "type" : "nested"
          }
        }
      }
    }
  }
}

The issue I am facing is that when I put the object into the index, the mapping does not work if there is more than one object stored inside the history field. In Kibana the history field is stored as follows:

{
  "color": "w",
  "from": "g2",
  "to": "g4",
  "flags": "b",
  "piece": "p",
  "san": "g4",
  "ts": {
    "$numberLong": "1586861525811"
  }
},
{
  "color": "b",
  "from": "e7",
  "to": "e5",
  "flags": "b",
  "piece": "p",
  "san": "e5",
  "ts": {
    "$numberLong": "1586861527710"
  }
},
{
  "color": "w",
  "from": "f2",
  "to": "f4",
  "flags": "b",
  "piece": "p",
  "san": "f4",
  "ts": {
    "$numberLong": "1586861531620"
  }
},
{
  "color": "b",
  "from": "d8",
  "to": "h4",
  "flags": "n",
  "piece": "q",
  "san": "Qh4#",
  "ts": {
    "$numberLong": "1586861533363"
  }
}

The different nested fields i specified in the mapping are not populated.

Is there something wrong with my mapping? It seems to work if the history field only has one object for example:

"history":
		{"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}}

But with more than one objects, it fails to map correctly. What could be the problem?

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