Elasticsearch 错误“无法在路径下找到嵌套对象”

And*_*iss 3 c# elasticsearch nest

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

查询 Elasticsearch 时出现以下错误:

[nested] 未能在路径 [departures] 下找到嵌套对象

我正在运行的查询如下:

{
    "explain":true,
    "from":0,
    "query":{
        "nested":{
            "path":"departures",
            "query":{
                "term":{
                    "departures.yearMonth":{
                        "value":202007
                    }
                }
            }
        }
    },
    "size":20
}
Run Code Online (Sandbox Code Playgroud)

我的映射如下:

{
    "tours":{
        "mappings":{
            "properties":{
                "departures":{
                    "type":"nested",
                    "properties":{
                        "guaranteed":{
                            "type":"boolean"
                        },
                        "spacesRemaining":{
                            "type":"long"
                        },
                        "startDate":{
                            "type":"date"
                        },
                        "yearMonth":{
                            "type":"long"
                        }
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

最后,从 Kibana 截取的屏幕截图显示我的索引中有一个有效条目。 在此处输入图片说明

任何想法为什么这个查询会像这样失败?

Alk*_*ris 5

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

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

ignore_unmapped (可选,布尔值)指示是否忽略未映射的路径并且不返回任何文档而不是错误。默认为假。

如果为 false,并且路径是未映射的字段,则 Elasticsearch 将返回错误。

您可以使用此参数查询可能不包含字段路径的多个索引。

  • 您的映射不会阻止对具有其他字段的文档建立索引。检查此 https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html 。您可以尝试将设置更改为“strict”,以便在尝试保存与您指定的内容“不同”的内容时抛出异常。这是测试环境吗?你能尝试一下吗? (2认同)