gpt4 book ai didi

Elasticsearch 5 结合 bool 术语和嵌套术语过滤器

转载 作者:行者123 更新时间:2023-12-02 22:49:01 24 4
gpt4 key购买 nike

有嵌套查询术语过滤器的文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html和 bool 项过滤器 https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-bool-query.html

嵌套是对象数组。不只是反对。那就是我不能使用简单的 bool term 过滤器。

我的查询看起来像:

{
"query": {
"bool": {
"filter": [
{
"term": {
"access_account.nid": 17,
"destroyed_at": null
}
}
],
"must": {
"match_all": {}
}
},
"nested": {
"path": "categories",
"query": {
"bool": {
"filter": [
{
"terms": {
"categories.id": [
15, 17
]
}
}
]
}
}
}
}
}

过滤器是数组,因为实际上我有更多的过滤器。

我收到了这个回复reason": "[bool] 格式错误的查询,预计 [END_OBJECT] 但找到 [FIELD_NAME]"

有没有什么解决方案可以组合父项/嵌套项过滤器?官方文档没有帮助。

我的 Elastic 版本是 5.4

谢谢。

最佳答案

你就快完成了,你的嵌套查询只需要进入bool/filter子句:

{
"query": {
"bool": {
"filter": [
{
"term": {
"access_account.nid": 17,
"destroyed_at": null
}
},
{
"nested": {
"path": "categories",
"query": {
"bool": {
"filter": [
{
"terms": {
"categories.id": [
15,
17
]
}
}
]
}
}
}
}
]
}
}
}

关于Elasticsearch 5 结合 bool 术语和嵌套术语过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45153819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com