1

我正在尝试根据字段创建不同的计数命中,但我被卡住了。

如何将基数和条件结合起来"select distinct(lastname) from table where name like 'George%'"

如何在 Cardinality 中使用“where”条件?

{
    "aggs" : {
        "test_count" : {
            "cardinality" : {
                "field" : "lastname"
            }
        }
    }
}
4

1 回答 1

0

您是否尝试过以下方法来获得不同的姓氏计数,firstName例如“乔治”

curl -X POST "http://localhost:9200/gccount/Customer/_search?pretty=true" -d'                       
{                                                                                                   
   "query": {                                                                                       
    "fuzzy_like_this_field" : {                                                                     
        "firstName" : {                                                                                  
            "like_text" : "George",                                                               
            "max_query_terms" : 12                                                                  
        }                                                                                           
    }                                                                                               
   },                                                                                               
   "aggs": {                                                                                        
      "distinct_lastNames": {                                                                       
         "terms": {                                                                                 
            "field": "lastName"                                                                     
         }                                                                                          
      }                                                                                             
   }                                                                                                
}'  

analyzer它在 elasticsearch field中默认为我工作firstName

响应

  "aggregations": {
      "distinct_lastNames": {
         "buckets": [
            {
               "key": "Upd",
               "doc_count": 1
            }, 
            {
               "key": "Bale",
               "doc_count": 2
            }
         ]
      }
   }

参考,

https://github.com/prayagupd/gccount/blob/master/gccount-analytics/scripts/search_customer_like.sh#L21

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-flt-field-query.html

于 2014-09-08T18:06:49.533 回答