有多个没有特殊信息的唯一 ID。从这里开始,根据需要进行调整:
设置
PUT special_info
{
"mappings": {
"properties": {
"unique_id": {
"type": "keyword"
},
"information": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
同步
POST _bulk
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"abc","information":"Some data"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"abc","information":"Special Information"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"abc","information":"Some data"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"def","information":"Some data"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"def","information":"Special Information"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"def","information":"Some data"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"ghi","information":"Some data"}
{"index":{"_index":"special_info","_type":"_doc"}}
{"unique_id":"ghi","information":"Some data"}
查询
GET special_info/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"information.keyword": {
"value": "Special Information"
}
}
}
]
}
},
"_source": "unique_id",
"aggs": {
"by_unique_ids": {
"terms": {
"field": "unique_id"
}
}
}
}
屈服
...
"aggregations" : {
"by_unique_ids" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "abc",
"doc_count" : 2
},
{
"key" : "def",
"doc_count" : 2
},
{
"key" : "ghi",
"doc_count" : 2
}
]
}
}