gpt4 book ai didi

elasticsearch - 在Elasticsearch中增强查询

转载 作者:行者123 更新时间:2023-12-03 01:15:36 24 4
gpt4 key购买 nike

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

 {"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
我的查询出了什么问题?

最佳答案

那不是有效的DSL查询。
您应将字词查询字段的值指定为数组,即["Action"]

{"terms":{"genres":["Action"],"boost":1.1}} 
更改所有术语查询并执行查询。

关于elasticsearch - 在Elasticsearch中增强查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62681332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com