elasticSearch:如何折叠查询
我想获得包含两个不同部分的查询结果,
- 即带有字段 X 的查询文档并在其上折叠。
- ,查询没有字段 X 分页的文档
- 基于上面的查询
例如,我有文档:
docID | Field X |
---|---|
1 | a |
2 | a |
3 | null |
4 | b |
有 4 个文档,文档 1 和 2 具有相同的 X 值,文档 3 在 X 处没有值, doc 4 具有独特的价值。
所以目标文档应该是(1或2)、3和4,我需要在这里添加分页条件(from + size)
有什么办法可以做到这一点吗?现在我有一个折叠查询,但只能获取文档(1 或 2)
GET job_info/_search
{
"_source": false,
"aggregations": {
"total": {
"cardinality": {
"field": "x.keyword"
}
}
},
"collapse": {
"field": "x.keyword"
},
"from": 0,
"query": {
"bool": {
"must": [
{
"terms": {
"other_condition1": [
1101
]
}
},
{
"match": {
"other_condition1": {
"query": "abc"
}
}
}
]
}
},
"size": 10,
"track_total_hits": true
}
I'd like to get a query result with two different part,
- query docs with field X and collapse on it.
- query docs without field X
- pagination based on queries above
For example, I have docs:
docID | Field X |
---|---|
1 | a |
2 | a |
3 | null |
4 | b |
There are 4 docs, doc 1 and 2 have same X value, doc 3 have no value at X, doc 4 have unique value.
So the target docs should be (1 or 2), 3 and 4, and I need to add pagination condition (from + size)here
Is there any way to do this? now I have a collapse query but can only get doc(1 or 2)
GET job_info/_search
{
"_source": false,
"aggregations": {
"total": {
"cardinality": {
"field": "x.keyword"
}
}
},
"collapse": {
"field": "x.keyword"
},
"from": 0,
"query": {
"bool": {
"must": [
{
"terms": {
"other_condition1": [
1101
]
}
},
{
"match": {
"other_condition1": {
"query": "abc"
}
}
}
]
}
},
"size": 10,
"track_total_hits": true
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论