Multiple Indices Search: Failed to find nested object under path

Hi
I need to run a search query across multiple indices (say, idx-users and idx-meta). The mapping for each is different.
idx-users has a nested field (path: staysAt, field: staysAt.street), while idx-meta doesn't have this field.
I'm trying to do a simple search (/idx-users,idx-meta/_search), with function_score query, in which one of the functions is:

{
          "filter": {
            "nested": {
              "path": "staysAt",
              "query": {
                "term": {
                  "staysAt.street": "MGRoad"
                }
              }
            }
          },
          "weight": 1.5
}

Upon running this query, I'm facing the following error:

{
              "index": "idx-meta",
              "caused_by": {
                "type": "illegal_state_exception",
                "reason": "[nested] failed to find nested object under path [staysAt]"
              }
}

How can I successfully run my query, and have scores according to whichever filter functions match?

Elasticsearch: v7.0.0

I think what you are looking for is "ignore_unmapped" parameter.
ignore_unmapped:
Indicates whether to ignore an unmapped path and not return any documents instead of an error. Defaults to false .
If false , Elasticsearch returns an error if the path is an unmapped field.
You can use this parameter to query multiple indices that may not contain the field path .

Check the Doc: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html

1 Like

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