Query a list field of a nested object

Hey, I was wondering if you guys could help me out here.

The data I'm currently querying admits a nested field nodes, eg:

{
    "document_name": "Regulation 6966/76",
          "nodes": [
            {
              "content": {
                "industry": "finance",
                "tags": ["TAG 01", "TAG 02", "TAG 03"],
                  ...
               }
              }
            ]
     ...
}

I want to query the tags field by confronting it with a supplied list of query_tags.
If the intersection of the two lists is not empty, that node should be returned.

I wanted an exact match, so in the mappings I have:

                "tags": {
                    "type": "keyword",
                    "index": "not_analyzed",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }

Query:

GET documents/documents/_search
{
  "query": {
    "nested": {
      "path": "nodes",
      "query": {
        "bool": {
          "filter": [
            {
              "terms": {
                "nodes.content.tags": ["TAG 01", "TAG 02"]
              }
            }
          ]
        }
      },
      "inner_hits": {
        "_source": "nodes.content.*"
      }
    }
  }
}

The behavior of this query is highly unpredicted to an untrained eye like mine.

Sometimes it performs the expected task, sometimes not.
I've tried to investigate if the inconsistency was due to the white space but it does not seem to be.

I'm looking for two things:

  1. Is there something obviously wrong here.
  2. Suggestions on how to perform this task in any other way.

Thanks

hey,

is is possible, that you tried to update the existing mapping? If so, this is not possible. You can check that by retrieving the mapping from the index.

Also, can you try using nodes.content.tags.keyword as the field to filter on?

If none of this solves your issue, a full reproduction is needed, including the index creating with its mapping and sample documents, otherwise it is super hard to follow.

--Alex

Hey,

Thanks for your reply. In fact, I needed to use keyword.

However, the problem was in the inner hit query.

From the docs:

`Inner hits support the following options:

from

The offset from where the first hit to fetch for each inner_hits in the returned regular search hits.

size: The maximum number of hits to return per inner_hits. By default the top three matching hits are returned`

Not reading carefully the documentation cost me all these hours.

Thanks anyway.

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