2014-06-19 2 views
0

부울 쿼리를 사용하여 elasticsearch에서 여러 쿼리를 결합하려고하지만 결과가 예상 한 것과 다릅니다. 예를 들면 :부울 쿼리로 쿼리 결합 Elasticsearch

내가 (다른 사람의 사이에서) 다음과 같은 서류가있는 경우 :

DOC 1: 
{ 
    "name":"Iphone 5", 
    "product_suggestions":{ 
     "input":[ 
     "iphone 5", 
     "apple" 
     ] 
    }, 
    "description":"Iphone 5 - The almost last version", 
    "brand":"Apple", 
    "brand_facet":"Apple", 
    "state_id":"2", 
    "user_state_description":"Almost New", 
    "product_type_id":"1", 
    "current_price":350, 
    "finish_date":"2014/06/20 14:12", 
    "finish_date_ms":1403273520 
} 

DOC 2: 
{ 
    "name":"Apple II Lisa", 
    "product_suggestions":{ 
     "input":[ 
     "apple ii lisa", 
     "apple" 
     ] 
    }, 
    "description":"Make a offer and I Apple II Lisa!!", 
    "brand":"Apple", 
    "brand_facet":"Apple", 
    "state_id":"2", 
    "user_state_description":"Used", 
    "product_type_id":"1", 
    "current_price":150, 
    "finish_date":"2014/06/15 16:12", 
    "finish_date_ms":1402848720 
} 

DOC 3: 
{ 
    "name":"Iphone 5s", 
    "product_suggestions":{ 
     "input":[ 
     "iphone 5s", 
     "apple" 
     ] 
    }, 
    "description":"Iphone 5s 32Gb like new with a few scratches bla bla bla", 
    "brand":"Apple", 
    "brand_facet":"Apple", 
    "state_id":"1", 
    "user_state_description":"New", 
    "product_type_id":"2", 
    "current_price":510.1, 
    "finish_date":"2014/06/10 14:12", 
    "finish_date_ms":1402409520 
} 

DOC 4: 
{ 
    "name":"Iphone 4s", 
    "product_suggestions":{ 
     "input":[ 
     "iphone 4s", 
     "apple" 
     ] 
    }, 
    "description":"Iphone 4s 16Gb Mint conditions and unlocked to all network", 
    "brand":"Apple", 
    "brand_facet":"Apple", 
    "state_id":"1", 
    "user_state_description":"Almost New", 
    "product_type_id":"2", 
    "current_price":385, 
    "finish_date":"2014/06/12 16:12", 
    "finish_date_ms":1402589520 
} 

와 나는 다음과 같은 쿼리합니다 (finish_date_ms보다 더 큰 것을 키워드 "애플"모든 문서와 측면을 가져 오기를 실행하는 경우

{ 
    "took":5, 
    "timed_out":false, 
    "_shards":{ 
     "total":5, 
     "successful":5, 
     "failed":0 
    }, 
    "hits":{ 
     "total":1, 
     "max_score":0.18392482, 
     "hits":[ 

     ] 
    }, 
    "facets":{ 
     "brand":{ 
     "_type":"terms", 
     "missing":0, 
     "total":1, 
     "other":0, 
     "terms":[ 
      { 
       "term":"Apple", 
       "count":1 
      } 
     ] 
     }, 
     "product_type_id":{ 
     "_type":"terms", 
     "missing":0, 
     "total":1, 
     "other":0, 
     "terms":[ 
      { 
       "term":1, 
       "count":1 
      } 
     ] 
     }, 
     "state_id":{ 
     "_type":"terms", 
     "missing":0, 
     "total":1, 
     "other":0, 
     "terms":[ 
      { 
       "term":2, 
       "count":1 
      } 
     ] 
     } 
    } 
} 

을 만 반환해야합니다 : 1,402,869,581)

{ 
    "from" : 1, 
    "size" : 20, 
    "query" : { 
    "bool" : { 
     "must" : { 
     "query_string" : { 
      "query" : "apple", 
      "default_operator" : "and", 
      "analyze_wildcard" : true 
     } 
     }, 
     "must_not" : { 
     "range" : { 
      "finish_date_ms" : { 
      "from" : null, 
      "to" : 1402869581, 
      "include_lower" : true, 
      "include_upper" : false 
      } 
     } 
     } 
    } 
    }, 
    "facets" : { 
    "brand" : { 
     "terms" : { 
     "field" : "brand_facet", 
     "size" : 10 
     } 
    }, 
    "product_type_id" : { 
     "terms" : { 
     "field" : "product_type_id", 
     "size" : 10 
     } 
    }, 
    "state_id" : { 
     "terms" : { 
     "field" : "state_id", 
     "size" : 10 
     } 
    } 
    } 
} 

이 반환 문서 DOC1. 범위 쿼리를 제거하면 Apple 단어가있는 모든 문서를 반환합니다. "용어"쿼리를 수정하면 n 문서가 반환되므로 문제가 범위 쿼리에 있다고 가정합니다.

누구나 올바른 방향으로 나를 가리킬 수 있습니까?

또 다른 중요한 점은이 모든 쿼리가 java (이 도움말)에 구현된다는 것입니다. 감사합니다. (이 거대한 게시물에 대한 sory)

+0

쿼리 할 필드의 MUST 절에서 ... –

+0

필드 이름을 입력하지 않은 이유는 모든 필드에서 쿼리를 원합니다. – amachado

답변

0

내 실수를 발견했다. (정가 초보자 실수)

문제는 범위 쿼리에 있지만 Json의 구걸에 문제가 아니 었습니다. 보낸 사람 필드가 1로 설정되었지만 결과는 단 하나의 레코드이므로 0이어야합니다!

모든 사항에 감사드립니다.