过滤的嵌套布尔查询。我不确定为什么没有对此进行记录。也许有人可以告诉我?
这是查询:
GET /test/object/_search
{
"from": 0,
"size": 20,
"sort": {
"_score": "desc"
},
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"state": 1
}
}
]
}
},
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"name": "foo"
}
},
{
"match": {
"name": "bar"
}
}
],
"should": [
{
"match": {
"has_image": {
"query": 1,
"boost": 100
}
}
}
]
}
},
{
"bool": {
"must": [
{
"match": {
"info": "foo"
}
},
{
"match": {
"info": "bar"
}
}
],
"should": [
{
"match": {
"has_image": {
"query": 1,
"boost": 100
}
}
}
]
}
}
],
"minimum_should_match": 1
}
}
}
}
}
在伪sql中:
SELECT * FROM /test/object
WHERE
((name=foo AND name=bar) OR (info=foo AND info=bar))
AND state=1
请记住,它是如何在内部处理name = foo的,这取决于您的文档字段分析和映射。这可以从模糊行为到严格行为不等。
“ minimum_should_match”:1表示,应该至少一个should语句为真。
此语句意味着只要结果集中有一个包含has_image:1的文档,它就会增加100倍。这将更改结果的顺序。
"should": [
{
"match": {
"has_image": {
"query": 1,
"boost": 100
}
}
}
]
玩得开心:)