我正在尝试创建一个弹性搜索查询来匹配数组内对象内的多个字段。
例如,我正在查询的 Elastic Search 结构类似于以下内容:
"hits": [
{
"_index": "titles",
"_type": "title",
...
"_source": {
...
"genres": [
{
"code": "adventure",
"priority": 1
},
{
"code": "action",
"priority": 2
},
{
"code": "horror",
"priority": 3
}
],
...
},
...
]
Run Code Online (Sandbox Code Playgroud)
我想做的是匹配具有特定类型/优先级配对的标题。例如,我尝试将所有标题与code=actionand匹配priority=1,但我的查询返回太多结果。在此示例中,由于流派列表包含与 匹配的流派以及code=action另一个与 匹配的流派,因此出现了上述标题priority=1。我的查询类似于以下内容:
"query": {
"bool": {
"filter": [
{
"bool": {
"must":[
{"term": {
"genres.code": {
"value": "action",
"boost": 1.0
}
}},
{"term": {
"genres.priority": {
"value": 1,
"boost": 1.0 …Run Code Online (Sandbox Code Playgroud)