2013-08-28 2 views
2

저는 오늘 Elasticsearch로 벽에 머리를 내고 실패한 테스트 케이스를 수정하려고했습니다. 나는 레일 3.2.14을 사용하고Elasticsearch는 NOT 필터를 적용하지 않습니다.

은 루비 1.9.3, 타이어 보석 및 ElasticSearch은 0.90.2

목적은 쿼리 반환 매칭 EXCLUDING에게 항목을 초래하는 것입니다 경우 vid == "ABC123xyz"

Video 모델의 루비 코드는 다음과 같습니다

def related_videos(count) 
    Video.search load: true do 
    size(count) 
    filter :term, :category_id => self.category_id 
    filter :term, :live => true 
    filter :term, :public => true 
    filter :not, {:term => {:vid => self.vid}} 
    query do 
     boolean do 
     should { text(:_all, self.title, boost: 2) } 
     should { text(:_all, self.description) } 
     should { terms(:tags, self.tag_list, minimum_match: 1) } 
     end 
    end 
    end 
end 

타이어에 의해 생성 된 결과 검색 쿼리처럼 보인다 이 :

{ 
    "query":{ 
    "bool":{ 
     "should":[ 
     { 
      "text":{ 
      "_all":{ 
       "query":"Top Gun","boost":2 
      } 
      } 
     }, 
     { 
      "text":{ 
      "_all":{ 
       "query":"The macho students of an elite US Flying school for advanced fighter pilots compete to be best in the class, and one romances the teacher." 
      } 
      } 
     }, 
     { 
      "terms":{ 
      "tags":["top-gun","80s"], 
      "minimum_match":1 
      } 
     } 
     ] 
    } 
    }, 
    "filter":{ 
    "and":[ 
     { 
     "term":{ 
      "category_id":1 
     } 
     }, 
     { 
     "term":{ 
      "live":true 
     } 
     }, 
     { 
     "term":{ 
      "public":true 
     } 
     }, 
     { 
     "not":{ 
      "term":{ 
      "vid":"ABC123xyz" 
      } 
     } 
     } 
    ] 
    }, 
    "size":10 
} 

ElasticSearch에서 결과 JSON :

{ 
    "took": 7, 
    "timed_out": false, 
    "_shards":{ 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total":1, 
    "max_score":0.2667512, 
    "hits":[ 
     { 
     "_index":"test_videos", 
     "_type":"video", 
     "_id":"8", 
     "_score":0.2667512, 
     "_source":{ 
      "vid":"ABC123xyz", 
      "title":"Top Gun", 
      "description":"The macho students of an elite US Flying school for advanced fighter pilots compete to be best in the class, and one romances the teacher.", 
      "tags":["top-gun","80s"], 
      "category_id":1, 
      "live":true, 
      "public":true, 
      "featured":false, 
      "last_video_view_count":0, 
      "boost_factor":0.583013698630137, 
      "created_at":"2013-08-28T14:24:47Z" 
     } 
     } 
    ] 
    } 
} 

누군가가 도움을 줄 수! Elasticsearch 용 문서는이 주제를 중심으로 드문 데, 아이디어가 부족합니다.

감사 최상위이 쿼리의 결과를 필터링하지 않습니다 당신이 방법을 필터링 사용

답변

0

- 그냥 패싯 카운트 같은 것들에서 결과를 필터링합니다. elasticsearch documentation for filter에는 더 자세한 설명이 있습니다. 나는이 시도하지만이 타이어 보석에서 지원됩니다 같은 불행하게도, 그것은하지 않는 것,

Video.search load: true do 
    query do 
    filtered do 
     boolean do 
     should { text(:_all, self.title, boost: 2) } 
     should { text(:_all, self.description) } 
     should { terms(:tags, self.tag_list, minimum_match: 1) } 
     end 
     filter :term, :category_id => self.category_id 
     filter :term, :live => true 
     filter :term, :public => true 
     filter :not, {:term => {:vid => self.vid}} 
    end 
    end 
end 
+0

안녕 :

당신은 약간 다릅니다 및 쿼리 절의 결과를 필터링하는 filtered query 할 필요가있다. 부울 블록은 FilteredQuery 객체 내에 구현되지 않습니다. https://github.com/karmi/tire/blob/04cce99c2b341eb37f60ff6a11fa459d4c073e12/lib/tire/search/query.rb – wildtangent

+0

'must_not'옵션을 사용하는 것이 더 쉬울 수도 있습니다. 부울 블록? 이것은 작동하지만 성능이 저하되는지 궁금합니다. – wildtangent

+0

필자는 특정 쿼리를 시도하지 않았다고 고백해야합니다. 필터가 최상위 수준이 아닌 필터링 된 쿼리 내에 있어야하는 방법을 나타내는 것입니다. – Shadwell

관련 문제