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的过滤路径