2016-10-20 2 views
0

안녕하세요, Elasticsearch에서이 작업을 수행하고 싶습니다.Elastic 검색의 OR 연산자 AND 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": { "쿼리"} 를 "윤활" }], "해야": [{ "일치": { "한 brandname": "아큐" } } , { "일치": { "브랜드 이름": "퍼포" } } } } –

0

이 쿼리는 조건을 충족시킵니다.

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