0

我正在搜索以下索引(示例如下所示):

 {"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":9742,"max_score":1.0,"hits":[{"_index":"movies","_type":"movies","_id":"oCKST3uxSjKmk_v4jQx7EA","_score":1.0,"_source":{"movieId":"1","title":"Toy Story (1995)","genres":"Adventure|Animation|Children|Comedy|Fantasy"}
},{"_index":"movies","_type":"movies","_id":"qO4XOZGFRyC95aN4pmhl_g","_score":1.0,"_source":{"movieId":"19","title":"Ace Ventura: When Nature Calls (1995)","genres":"Comedy"}
},{"_index":"movies","_type":"movies","_id":"nvm12M_ASG-JN4UW7-xr2Q","_score":1.0,"_source":{"movieId":"20","title":"Money Train (1995)","genres":"Action|Comedy|Crime|Drama|Thriller"}
},{"_index":"movies","_type":"movies","_id":"tpUXECgVSdyZxGg3NnFUlQ","_score":1.0,"_source":{"movieId":"24","title":"Powder (1995)","genres":"Drama|Sci-Fi"}
},{"_index":"movies","_type":"movies","_id":"SIe1AswBTdOvh3rzTTB3-A","_score":1.0,"_source":{"movieId":"26","title":"Othello (1995)","genres":"Drama"}
},{"_index":"movies","_type":"movies","_id":"b2kocluIRyCkVkyG8mWdkg","_score":1.0,"_source":{"movieId":"28","title":"Persuasion (1995)","genres":"Drama|Romance"}
},{"_index":"movies","_type":"movies","_id":"Sh5A1I7eSmGp4zy4jC3NJA","_score":1.0,"_source":{"movieId":"30","title":"Shanghai Triad (Yao a yao yao dao waipo qiao) (1995)","genres":"Crime|Drama"}
},{"_index":"movies","_type":"movies","_id":"tzarINl_TZGQBc6KBsmwdQ","_score":1.0,"_source":{"movieId":"34","title":"Babe (1995)","genres":"Children|Drama"}
},{"_index":"movies","_type":"movies","_id":"j_yVutoxR4OkwKc6cZGUug","_score":1.0,"_source":{"movieId":"36","title":"Dead Man Walking (1995)","genres":"Crime|Drama"}
},{"_index":"movies","_type":"movies","_id":"tNt7AZekTX6wq9pjniqY5A","_score":1.0,"_source":{"movieId":"50","title":"Usual Suspects, The (1995)","genres":"Crime|Mystery|Thriller"}
}]}}

我在上述索引上使用以下查询正文:

{
    "query":{
        "bool":{
            "should":[
                {"terms":{"genres":"Action","boost":1.1} },
                {"terms":{"genres":"Adventure","boost":1.4} },
                {"terms":{"genres":"Mystery","boost":1.0} },
                {"terms":{"genres":"Sci-Fi","boost":1.1} },
                {"terms":{"genres":"Comedy","boost":4.0} },
                {"terms":{"genres":"Crime","boost":0.5} },
                {"terms":{"genres":"Thriller","boost":0.3} },
                {"terms":{"genres":"Romance","boost":0.4} },
                {"terms":{"genres":"Drama","boost":0.8} },
                {"terms":{"genres":"Fantasy","boost":0.5} },
                {"terms":{"genres":"Horror","boost":0.1} },
                {"terms":{"genres":"War","boost":0.2} },
                {"terms":{"genres":"Children","boost":0.9} },
                {"terms":{"genres":"Animation","boost":0.3} },
                {"terms":{"genres":"Musical","boost":0.4} }
                        ]
                }
            }
    }

但是 ES 给了我错误:

 nested: QueryParsingException[[movies] [terms] query does not support [genres]]; }]",
    "status": 400

我的查询有什么问题?

4

1 回答 1

1

这不是一个有效的 DSL 查询。

您应该将术语查询字段的值指定为数组,即["Action"]

{"terms":{"genres":["Action"],"boost":1.1}} 

更改所有术语查询并执行查询。

于 2020-07-01T16:55:13.573 回答