Query nested object array with Java API


(Andy) #1

Hi,

I am a noob and I am trying to use Java API to query a nested object array. Here's the mapping:

mappings": {
      "tag": {
        "properties": {
          "entities": {
            "properties": {
              "type": {
                "type": "string",
                "index": "not_analyzed",
                "store": true
              },
              "value": {
                "type": "string",
                "index": "not_analyzed",
                "store": true
              }
            }
          },
          "tag_id": {
            "type": "string",
            "index": "not_analyzed",
            "store": true
          }
        }
      }
    }

I am trying to query with the following:

client().prepareSearch(INDEX)
.setTypes(INDEX_TYPE)
.setFetchSource(false)
.setVersion(false)
.setQuery(query)
.setSize(10)
.addField(TAG_ID)
.addFieldDataField(ENTITIES)
.get()
.getHits();

I can see the tag ID and entity field but there's nothing under the entity data field where there supposed to be an array of entities.

But from sense I can see:

      "tag_id": "0276f681-c417-41c4-90d3-d91292e0a5c0",
      "entities": [
        {
          "type": "url",
          "value": "http://www.abc.com"
        },
        {
          "type": "url",
          "value": "http://www.xyz.com"
        }

What did I do wrong in Java?

Thank you.

Regards,
Andy


(system) #2