2014-07-09 4 views
7

저는 신축성있는 검색을 배우고 있으며 고유 한 값을 계산하려고합니다. 지금까지는 가치를 셀 수 있지만 별개의 것은 아닙니다.elasticsearch를 사용하여 고유 한 값 계산

curl http://localhost:9200/store/item/ -XPOST -d '{ 
    "RestaurantId": 2, 
    "RestaurantName": "Restaurant Brian", 
    "DateTime": "2013-08-16T15:13:47.4833748+01:00" 
}' 

curl http://localhost:9200/store/item/ -XPOST -d '{ 
    "RestaurantId": 1, 
    "RestaurantName": "Restaurant Cecil", 
    "DateTime": "2013-08-16T15:13:47.4833748+01:00" 
}' 

curl http://localhost:9200/store/item/ -XPOST -d '{ 
    "RestaurantId": 1, 
    "RestaurantName": "Restaurant Cecil", 
    "DateTime": "2013-08-16T15:13:47.4833748+01:00" 
}' 

그리고 내가 지금까지 시도 :

curl -XPOST "http://localhost:9200/store/item/_search" -d '{ 
    "size": 0, 
    "aggs": { 
    "item": { 
     "terms": { 
     "field": "RestaurantName" 
     } 
    } 
    } 
}' 

는 출력 :

{ 
    "took": 0, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 3, 
    "max_score": 0.0, 
    "hits": [] 
    }, 
    "aggregations": { 
    "item": { 
     "buckets": [ 
     { 
      "key": "restaurant", 
      "doc_count": 3 
     }, 
     { 
      "key": "cecil", 
      "doc_count": 2 
     }, 
     { 
      "key": "brian", 
      "doc_count": 1 
     } 
     ] 
    } 
    } 
} 

가 어떻게 cecil 대신 1 등의 수를 얻을 수 있습니다 여기에

는 샘플 데이터입니다 2

답변

4
+0

curl -XPOST "http : // localhost : 9200/store/item/_search"-d '{ "size": 0, "aggs": { "item": { "카디널리티" "field": "RestaurantName"}}}} '그러나 뚜렷한 카운트를 얻지 못함 – Developer

+0

curl -XGET이어야합니까? – c24b

+0

그리고 항목으로 집계 이름을 바꾸어도 괜찮습니까? – c24b

3

당신은 당신이 doc

curl -XGET "http://localhost:9200/store/item/_search" -d' 
{ 
"aggs" : { 
    "restaurant_count" : { 
     "cardinality" : { 
      "field" : "RestaurantName", 
      "precision_threshold": 100, 
      "rehash": false 
      } 
      } 
     } 
}' 
이 나를 위해 일

에서 찾을 수 @coder에 의해 했나요으로 카디널리티 옵션을 사용할 필요가 ...

0

아무 지원도 없다 결정적이지 않은 계산이 존재하더라도 ElasticSearch의 고유 카운팅에 사용됩니다. 결과에 "용어"집계 및 개수 버킷을 사용하십시오. Count distinct on elastic search 질문을 참조하십시오.

관련 문제