Php 我能';t使用弹性搜索进行创建和请求
我想用ES发出一个Php 我能';t使用弹性搜索进行创建和请求,php,
elasticsearch,doctrine,Php,
elasticsearch,Doctrine,我想用ES发出一个和请求,所以我在boolQuery中的术语之间(对于标记.id)放置了一个必须,但它不起作用。。。我接收元素,但像或 { "query": { "bool": { "must": [ { "terms": { "computerId": [ 1 ] } }, { "nest
和请求,所以我在boolQuery
中的术语之间(对于标记.id
)放置了一个必须,但它不起作用。。。我接收元素,但像或
{
"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
}
}
}
}
}
]
}
}
}
术语的行为类似于或,因此您的查询是AND(1、2或3)
术语查询返回在提供的字段中包含一个或多个确切术语的文档
希望这对你有所帮助你想实现什么?1、2和3?没错,我只想要具有三个标记.id
的对象,但通过此查询,我会收到几乎与其中一个标记.id
匹配的所有对象,请参见我的答案。如果你有任何问题,请告诉我。3个嵌套?这是个好习惯?我测试了一下,然后告诉你。谢谢你,如果你的对象看起来像:tags:[{id:1},{id:2},{id:3}],那么这就是在内部对象之间进行操作的方式。啊,好的,这正是我得到的对象,我正在寻找用3嵌套在内部来构建查询的方法。因为在我得到一个嵌套之前,它是我的方法的输出,很高兴它能工作。请看