您好我想在Elasticsearch中实现这一目标。
select * from products where brandName = Accu or brandName = Perfor AND cat=lube(any where in any filed of an elastic search ).
我在Elasticsearch中使用此查询。
{
"bool": {
"must": {
"query_string": {
"query": "oil"
}
},
"should": [
{
"term": {
"BrandName": "Accu"
}
},
{
"term": {
"BrandName": "Perfor"
}
}
]
}
}
通过此查询,我得不到组合的确切结果。
答案 0 :(得分:1)
如果您的minimum_should_match: 1
字段是已分析的字符串,则需要在查询中添加match
,并可能使用term
代替BrandName
。
{
"bool" : {
"must" : {
"query_string" : {
"query" : "oil OR lube OR lubricate"
}
},
"minimum_should_match": 1, <---- add this
"should" : [ {
"match" : {
"BrandName" : "Accu"
}
}, {
"match" : {
"BrandName" : "Perfor"
}
} ]
}
}
答案 1 :(得分:0)
此查询符合您的条件。
{
"bool" : {
"must" : { "term" : { "cat" : "lube" } },
"should" : [
{ "term" : { "BrandName" : "Accu" } },
{ "term" : { "BrandName" : "Perfor" } }
],
"minimum_should_match" : 1
}
}