我有下面的JSON数据,我想在Elasticsearch中写一个查询,查询是,(给我所有"ai_id“的值=0的实体)。
JSON数据列表:
{
"_index": "try1",
"_type": "_doc",
"_id": "2",
"_score": 1,
"_source": {
"target": {
"br_id": 0,
"an_id": 0,
"ai_id": 0,
"explanation": [
"element 1",
"element 2"
]
},
"process": {
"an_id": 1311,
"pa_name": "micha"
},
"text": "hello world"
}
},
{
"_index": "try1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"target": {
"br_id": 0,
"an_id": 1,
"ai_id": 1,
"explanation": [
"element 3",
"element 4"
]
},
"process": {
"an_id": 1311,
"pa_name": "luca"
},
"text": "the all People are good"
}
}
]
}
}我试过了,但似乎不起作用,请帮助我将不胜感激。
GET try1\_search
{
"query":{
{ "match_all": { "ai_id": 0}}
}
}这也不起作用,
GET try1/_search
{
"query": {
"nested" : {
"query" : {
"must" : [
{ "match" : {"ai_id" : 0} }
]
}
}
}
}请给我一个建议。thx
发布于 2019-07-11 00:09:55
您需要像这样查询嵌套在target对象上的查询-
GET /try1/_search
{
"query": {
"nested" : {
"path" : "target",
"query" : {
"bool" : {
"must" : [
{ "match" : {"target.ai_id" : 0} }
]
}
}
}
}
}参考 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
https://stackoverflow.com/questions/56974295
复制相似问题