Search specific offset value of array type

I have a index have such mapping

{
  "band": {
    "properties": {
      "device_id": {
        "type": "string"
      },
      "sac": {
        "type": "string"
      },
      "session_no": {
        "type": "long"
      },
      "interval": {
        "type": "long"
      },
      "sac_next": {
        "type": "string"
      },
      "sac_prev": {
        "type": "string"
      },
      "timestamp": {
        "type": "long"
      }
    }
  }
}

And there are documents like.

{
  "_index": "jpl_eventflow_test",
  "_type": "xxx",
  "_id": "AVkBSy0IDdRbCudoQaO4",
  "_score": 1,
  "_source": {
    "device_id": "96D1B243-FE54-480B-AC9D-A3650B0E00FF",
    "interval": 2,
    "timestamp": 1481657475,
    "session_no": 0,
    "sac_prev": [
      "news",
      "posts",
      "posts"
    ],
    "sac": "news",
    "sac_next": [
      "news_item",
      "post_detail", // <---- want to search documents that second of elements having 'post_detail' value.
      "post_detail"
    ]
  }
}

So, How can I search documents which sac_next[1]:"post_detail" ?
I mean want to search value not only field but also array offset targeted.

I think the answer of this question is here.

It says

Arrays of objects
Arrays of objects do not work as you would expect: you cannot query each object independently of the other objects in the array. If you need to be able to do this then you should use the nested datatype instead of the object datatype.

This is explained in more detail in Nested datatype.

There isn't positional information indexed about arrays. Nesting doesn't change that.

In order to search by both position and value, you'll have to enrich your data to explicitly include those.

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