将旧的ElasticSearch查询转换为较新的ElasticSearch版本时,我们遇到了很多麻烦。 ES 1.8的原始查询是:
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*",
"default_operator": "AND"
}
},
"filter": {
"and": [
{
"terms": {
"organization_id": [
"fred"
]
}
}
]
}
}
},
"size": 50,
"sort": {
"updated": "desc"
},
"aggs": {
"status": {
"terms": {
"size": 0,
"field": "status"
}
},
"tags": {
"terms": {
"size": 0,
"field": "tags"
}
}
}
}
我们正在尝试将其转换为ES版本7。有人知道该怎么做吗?
最佳答案
6.8中的Filtered query的Elasicsearch文档(我可以找到具有页面的文档的最新版本)指出,应将查询移动并过滤到must
查询中的filter
和bool
参数。
另外,terms
聚合不再支持将size
设置为0以获得Integer.MAX_VALUE
。如果确实需要所有条款,则需要将其明确设置为最大值(2147483647)。但是,Size的文档建议改为使用Composite聚合并分页。
以下是我可以对与Elasticsearch 7一起使用的原始内容进行的最接近的查询。
{
"query": {
"bool": {
"must": {
"query_string": {
"query": "*",
"default_operator": "AND"
}
},
"filter": {
"terms": {
"organization_id": [
"fred"
]
}
}
}
},
"size": 50,
"sort": {
"updated": "desc"
},
"aggs": {
"status": {
"terms": {
"size": 2147483647,
"field": "status"
}
},
"tags": {
"terms": {
"size": 2147483647,
"field": "tags"
}
}
}
}
关于elasticsearch - 如何将ElasticSearch查询转换为ES7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62763183/