2016-10-20 16 views
0

こんにちは私はElasticsearchでこれを実現したいと思います。Elastic検索のOR演算子とAND演算子

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

minimum_should_match: 1をクエリに追加する必要があります。BrandNameフィールドが解析された文字列の場合は、termの代わりにmatchを使用してください。

{ 
    "bool" : { 
    "must" : { 
     "query_string" : { 
     "query" : "oil OR lube OR lubricate" 
     } 
    }, 
    "minimum_should_match": 1,   <---- add this 
    "should" : [ { 
     "match" : { 
     "BrandName" : "Accu" 
     } 
    }, { 
     "match" : { 
     "BrandName" : "Perfor" 
     } 
    } ] 
    } 
} 
+0

おかげでたくさんヴァル... !!!!!!!!!!!!!!!!!!! –

+0

私は条件のいずれかがドキュメントをヒットする必要がある場合でも、複数の条件を持っている必要があります。 –

+0

{ "ブール":{ "必須":[{ "QUERY_STRING":{ "クエリ": "油" } }、{ "QUERY_STRING":{ "クエリ": "潤滑" } }、{ "QUERY_STRING":{ "クエリ": } }]、 "べき" "潤滑":[{ "一致":{ "新しい名称": "アキュ" は } を} 、{ "一致":{ "ブランド名": "Perfor" } } } } –

0

このクエリは条件を満たしています。

{ 
    "bool" : { 
     "must" : { "term" : { "cat" : "lube" } }, 
     "should" : [ 
      { "term" : { "BrandName" : "Accu" } }, 
      { "term" : { "BrandName" : "Perfor" } } 
     ], 
    "minimum_should_match" : 1 
    } 
}