Elasticsearch 错误 "failed to find nested object under path"

Elasticsearch error "failed to find nested object under path"

我知道这个问题之前已经被问过多次,但是 none 现有的问题或答案对我有帮助。

查询 Elasticsearch 时出现以下错误:

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

我是运行的查询如下:

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

而我的映射如下:

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

最后,从 Kibana 截取的屏幕截图显示我的索引中有一个有效条目。

知道为什么这个查询会这样失败吗?

尝试在您的查询请求中将 ignore_unmapped 标志设置为 true

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.