Elasticsearch(027):es中Meta-Fields(元數據類型)之概述(_field_names)

概述

該_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"
        }
      }
    ]
  }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章