Nai*_*bal 5 elasticsearch elasticsearch-dsl elasticsearch-query
我在我的项目中使用 Elastic search 1.7 版本。我有一个名为的索引colleges,在该索引下有一个courses像这样的嵌套索引名称。
{
"name": "College Name"
"university": "University Name",
"city": 429,
"city_name": "London",
"state": 328,
"state_name": "London",
"courses": [
{
"id": 26,
"degree_name": "Master Of Technology",
"annual_fee": 100000,
"stream": "Engineering",
"degree_id": 9419
},
{
"id": 28,
"degree_name": "Master Of Philosophy",
"annual_fee": 100000,
"stream": "Philosophy",
"degree_id": 9420
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在做的是,我试图根据学院提供的嵌套的学院来state过滤degree_id学院courses。我想返回父对象的完整主体或所有字段colleges,即仅返回courses与查询匹配的字段。
我为完成任务而返回的查询是
{
"_source": false,
"query": {
"bool": {
"must": [
{
"term": {
"state": "328"
}
},
{
"nested": {
"path": "courses",
"query": {
"term": {
"courses.degree_id": 9419
}
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个查询工作正常,只返回那些与查询匹配的嵌套对象,但这个查询的错误是我声明了"_source":false in the parent object.
if I declare"_source": true then it returns me all the nested objects whether they meets the query or not. And the second way the query is working fine is to declare field names in"_source": ["field1", "field2", .... "field100 “] . But I have about 50 fields in the parent or colleges index. So i don't want to declare all the field names in_来源. Is there any other way to accomplish this without declaring all the field names in_来源`。
| 归档时间: |
|
| 查看次数: |
777 次 |
| 最近记录: |