我目前正在尝试将一个基于Solr的应用程序迁移到ElasticSearch。
我有一个Lucene查询:
((
name:(+foo +bar)
OR info:(+foo +bar)
)) AND state:(1) AND (has_image:(0) OR has_image:(1)^100)
据我所知,这是must
子句和布尔e1d1e的组合:
获取包含(foo AND bar in name) OR (foo AND bar in info)
的所有文档。之后,根据条件state=1
对结果进行过滤,并对包含图像的文档进行Boost。
我一直在尝试对must
使用布尔查询,但未能将布尔值OR
放入must
子句。这就是我所拥有的:
GET /test/object/_search
{
"from": 0,
"size": 20,
"sort": {
"_score": "desc"
},
"query": {
"bool": {
"must": [
{
"match": {
"name": "foo"
}
},
{
"match": {
"name": "bar"
}
}
],
"must_not": [],
"should": [
{
"match": {
"has_image": {
"query": 1,
"boost": 100
}
}
}
]
}
}
}
如您所见,缺少info
的must
条件。
更新
我已经更新了我的ElasticSearch查询,并删除了该函数分数。我的基本问题仍然存在。
3条答案
按热度按时间7fhtutme1#
示例:
您希望查看以下所有项目(圆形和(红色或蓝色)):
您还可以进行更复杂的OR运算,例如,如果您想要匹配5个中的至少3个,则可以在“应该”下指定5个选项,并将“Minimum_Share”设置为3。
多亏了格伦·汤普森和塞巴斯蒂亚隆索,他们发现了我以前筑巢的地方不太对。
还要感谢Fatmank指出,在ElasticSearch版本6中,“Term”变成了“Match”。
r3i60tvu2#
我最终成功地创建了一个查询,它执行的正是我想要的:
筛选的嵌套布尔查询。我不确定这为什么没有记录在案。也许这里有人能告诉我?
以下是查询:
在伪SQL中:
请记住,这取决于您的文档字段分析和Map如何在内部处理name=foo。这可能是模糊的行为,也可能是严格的行为。
“MINIMUM_HASH_MATCH”:1表示至少有一条应该语句必须为真。
这条语句意味着,只要结果集中有包含HAS_IMAGE:1的文档,它就会因数100而增加。这会更改结果顺序。
祝你们玩得开心:)
6uxekuva3#
这就是如何使用Kibana将多个布尔查询嵌套在一个外部布尔查询中,
这就是在ES中嵌套查询的方法
在“bool”中有更多的类型,
1.过滤器
1.不得