概述
該_field_names字段會索引文檔中所有包含非空值的字段名稱。_field_names字段用於存在查詢和缺失查詢的情況下,查詢指定指定字段擁有非空值的文檔是否存在。
注意:由於_field_names引入了一些索引時間開銷,因此,如果要優化索引速度並且不需要exists查詢,則可能需要禁用此字段。
使用示例
PUT example
PUT example/docs/_mapping
{
"properties":{
"id":{"type": "long"},
"title":{"type": "text"},
"content":{"type": "text"}
}
}
PUT example/docs/1
{
"id":1,
"title": "This is a title"
}
PUT example/docs/2
{
"id":2,
"title": "This is another a title!!",
"content": "content............"
}
PUT example/docs/3
{
"id":3,
"content": "content3333333333"
}
# 查詢title非空的文檔
GET example/docs/_search
{
"query": {
"exists": {
"field": "title"
}
}
}
返回結果
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "example",
"_type": "docs",
"_id": "2",
"_score": 1,
"_source": {
"id": 2,
"title": "This is another a title!!",
"content": "content............"
}
},
{
"_index": "example",
"_type": "docs",
"_id": "1",
"_score": 1,
"_source": {
"id": 1,
"title": "This is a title"
}
}
]
}
}