我想用ES发出AND
请求,因此我在must
中的术语之间(对于tags.id
)放入了boolQuery
,但是它不起作用...我收到的元素却像OR
{
"query": {
"bool": {
"must": [
{
"terms": {
"computerId": [
1
]
}
},
{
"nested": {
"path": "tags",
"query": {
"bool": {
"must": [
{
"terms": {
"tags.id": [
1,
2,
3
]
}
}
]
}
}
}
}
]
}
}
}
最佳答案
您应该在bool查询中使用nested
。
试试这个:
{
"query": {
"bool": {
"must": [
{
"terms": {
"computerId": [
1
]
}
},
{
"nested": {
"path": "tags",
"query": {
"term": {
"tags.id": {
"value": 1
}
}
}
}
},
{
"nested": {
"path": "tags",
"query": {
"term": {
"tags.id": {
"value": 2
}
}
}
}
},
{
"nested": {
"path": "tags",
"query": {
"term": {
"tags.id": {
"value": 3
}
}
}
}
}
]
}
}
}
术语的行为类似于OR,因此您的查询执行的是AND(1 OR 2 OR 3)。
Terms query returns documents that contain one or more exact terms in a provided field.
From Here
希望这可以帮助
关于php - 我无法通过Elastic Search进行AND请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59696373/