1.聚合去重
{
  "query" :{ "match_all":{}},
  "aggs": {
    "distinct_docField": {
      "cardinality": {
        "field": "docField"
      }
    }
  },
  "track_total_hits": true
}
针对
docField作去重统计,类似SQL:
  select count(distinct docField ) from tab
2.控制输出_source中输出字段
{
 "query" :{ "match_all":{}},
   "_source" : {
    "includes" : [ "docField"],
    "excludes" : [ "" ]  
  }
}
includes为需要保留的结果字段,只对_source中的字段有效
查询结果类似:
{
   "_index" : "index_name",
   "_type" : "_doc",
   "_id" : "10017313046",
   "_score" : 2.0,
   "hits" : {
     "hits" : [
       {
         "_source" : {
           "docField" : 10017313046
         }
       }, ...
     ]
  }
}
3.去除_index等默认字段(或只显示需要的字段)
POST INDEX_NAME/_search?filter_path=hits.hits._source.docField
{
 "query" :{ "match_all":{}},
   "_source" : {
    "includes" : [ "docField"],
    "excludes" : [ "" ]  
  }
}
查询结果类似:
{
  "hits" : {
    "hits" : [
      {
        "_source" : {
          "docField" : 10017313046
        }
      }, ...
      ]
      }
}
filter_path参数控制json的过滤路径
                  
                  
                  
                  
                            
                            
这篇博客介绍了如何在Elasticsearch中进行聚合去重统计,通过SQL语句的等效实现。同时,展示了如何控制查询结果中返回的_source字段,只保留特定字段如'docField'。此外,还提及了使用filter_path参数来过滤JSON响应,以便更专注于所需的数据。这些技巧对于优化数据检索和处理非常实用。
          
      
          
                
                
                
                
              
                
                
                
                
                
              
                
                
              
            
                  
					7340
					
被折叠的  条评论
		 为什么被折叠?
		 
		 
		
    
  
    
  
            


            