6

I know this has been asked multiple times before but none of the existing questions or answers have helped me.

I am getting the following error when querying Elasticsearch:

[nested] failed to find nested object under path [departures]

The query I am running is below:

{
    "explain":true,
    "from":0,
    "query":{
        "nested":{
            "path":"departures",
            "query":{
                "term":{
                    "departures.yearMonth":{
                        "value":202007
                    }
                }
            }
        }
    },
    "size":20
}

And my mapping is as follows:

{
    "tours":{
        "mappings":{
            "properties":{
                "departures":{
                    "type":"nested",
                    "properties":{
                        "guaranteed":{
                            "type":"boolean"
                        },
                        "spacesRemaining":{
                            "type":"long"
                        },
                        "startDate":{
                            "type":"date"
                        },
                        "yearMonth":{
                            "type":"long"
                        }
                    }
                }
            }
        }
    }
}

And finally, a screenshot taken from Kibana showing that there is a valid entry in my index. enter image description here

Any ideas why this query would be failing like this?

4
  • What version are you using? Commented Apr 6, 2020 at 23:52
  • Are you querying indices that do not have the nested field mapping? Commented Apr 7, 2020 at 4:26
  • @AlkisKalogeris Version is 7.5.2. Commented Apr 7, 2020 at 8:02
  • @RussCam In the mapping I posted in above, the type is nested. Commented Apr 7, 2020 at 8:03

1 Answer 1

8

Try setting the ignore_unmapped flag to true on your query request

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

ignore_unmapped (Optional, boolean) 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.

Sign up to request clarification or add additional context in comments.

5 Comments

Strange. So that stopped the error but is now not returning the expected results which suggests there's a mapping issue. However, the mapping I have posted clearly shows that the departures field is mapped as a nested type. Any ideas what might be going on here or suggestions to fix?
Your mapping doesn't prevent the indexing of a document that has other fields. Check this elastic.co/guide/en/elasticsearch/reference/current/… . You can try changing your setting to strict so it throws when try to save something "different" from what you've specified. Is this a testing environment? Can you try that?
Thanks a lot for the advice. This was not a test environment and I didn't actually have one as I've only recently started using Elastic. However, I set up a test environment and recreated my index with strict mapping and made sure everything was mapped correctly and I've now got a working search. Just need to rebuild the production environment and then hopefully I'm sorted. Thanks again for your guidance.
Hi @AndyFurniss, happy I could help. If it's not a bother, you can mark the answer. Have fun.
I'm running into this exact same problem. After double and triple-checking, it turns out the field I'm trying to access actually isn't nested, it's just one level down. I think it's very confusing that nested in elasticsearch doesn't mean what it sounds like, and has a much more specific meaning, where it's only really necessary to specify it for lists of objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.