2014-07-09 13 views
7

Uczę się elastycznego wyszukiwania i chciałbym policzyć różne wartości. Do tej pory mogę policzyć wartości, ale nie odrębne.Oblicz różne wartości za pomocą elasticsearch

Oto przykładowe dane:

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" 
}' 

A co starałem dotąd:

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

wyjściowa:

{ 
    "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 
     } 
     ] 
    } 
    } 
} 

Jak mogę uzyskać liczbę cecil jako 1 zamiast z 2

Odpowiedz

4
+0

Próbowałem nawet: curl -XPOST "http: // localhost: 9200/store/item/_search" -d '{"size": 0, "aggs": {"item": {"cardinality": { "field": "RestaurantName"}}}} ', ale nie otrzymuje wyraźnych liczb – Developer

+0

Powinien być zwinięty -XGET? – c24b

+0

i czy można zmienić nazwę agregatu jako przedmiotu? – c24b

3

Musisz użyć opcji liczności jak wymieniono przez @coder, które można znaleźć w doc

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

Ten pracował dla mnie ...

0

Nie ma wsparcie dla wyraźnego liczenia w ElasticSearch, chociaż istnieje niedeterministyczne liczenie. Skorzystaj z agregacji "pojęć" i zliczeń w wynikach. Zobacz pytanie: Count distinct on elastic search .

Powiązane problemy