2012-01-05 3 views
1

탄성 찾기를 사용하여 필터를 사용하여 연관된 두 모델의 링크 수를 계산하려고합니다.필터의 모든 결과를 반환하지 않고 필터의 조회수를 얻는 방법이 있습니까

나는 has_many vote라는 질문을 가지고 있습니다.

나는 인덱스는 각 투표의 ID를 질문 표에 대한 매핑을 가지고 있고,

curl -XGET localhost:9200/votes/_search -d '{query : {"constant_score" : {"filter" : { "term" : {"question_id" : 5} }, "boost" : 1.0 } }}' 

문제

이 모든 결과를 반환한다는 것이다 일을하고있다. 간단히 계산을 할 수 있습니까?

+0

는 측면의 그 생각이 아니다? http://www.elasticsearch.org/guide/reference/api/search/facets/ – phoet

답변

2

그냥 쿼리 문자열에 search_type=count을 추가

curl -XGET localhost:9200/votes/_search?search_type=count -d '{ 
    "query" : { 
     "constant_score" : { 
      "filter" : { "term" : {"question_id" : 5} } 
     } 
    } 
}' 

@phoet이 제안, 대신 측면을 사용할 수 있습니다, 말했다. 상위 10 개 질문에 대한 예를 들어

는 :

curl -XGET 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count' -d ' 
{ 
    "facets" : { 
     "votes" : { 
     "terms" : { 
      "field" : "question_id" 
     } 
     } 
    } 
} 
' 

또는 단지에 대한

는 5 question_id :

curl -XGET 'http://127.0.0.1:9200/votes/_search?pretty=1&search_type=count' -d ' 
{ 
    "query" : { 
     "constant_score" : { 
     "filter" : { 
      "term" : { 
       "question_id" : 5 
      } 
     } 
     } 
    }, 
    "facets" : { 
     "votes" : { 
     "terms" : { 
      "field" : "question_id" 
     } 
     } 
    } 
} 
' 
+0

탄성 검색에 타이어를 사용하고 있다면 search_type = count를 어떻게 추가합니까? –

+1

@RazorStorm [search_type 개수 쿼리] (https://github.com/karmi/tire/issues/100)는 아직 지원되지 않습니다. 문제의 해결 방법은 크기가 0으로 설정되어 있습니다. –

관련 문제