1. _index field

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-index-field.html

译文链接 : http://www.apache.wiki/display/Elasticsearch/_id+field

贡献者 : 朱彦安ApacheCNApache中文网

当跨多个索引执行查询时,有时需要添加仅与某些索引相关联的查询子句。该 _index字段允许在索引文档上进行索引的匹配。它可以在 termterms 查询,aggregations(聚合) , scripts(脚本) , sorting(排序)中使用 :

注意 :

_index 被表现为虚拟字段 - 它不会作为实际字段添加到 Lucene 索引。这意味着您可以使用 termterms 查询(或任何重写到 term 查询的查询,如 matchquery_stringsimple_query_string 查询) _index 字段,但不支持 prefix(前缀)wildcard(通配符)regexp(正则表达式)fuzzy(模糊查询)

# Example documents
curl -XPUT 'localhost:9200/index_1/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "text": "Document in index 1"
}
'
curl -XPUT 'localhost:9200/index_2/my_type/2?refresh=true&pretty' -H 'Content-Type: application/json' -d'
{
  "text": "Document in index 2"
}
'
curl -XGET 'localhost:9200/index_1,index_2/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "terms": {
      "_index": ["index_1", "index_2"] # 1
    }
  },
  "aggs": {
    "indices": {
      "terms": {
        "field": "_index", # 2
        "size": 10
      }
    }
  },
  "sort": [
    {
      "_index": { # 3
        "order": "asc"
      }
    }
  ],
  "script_fields": {
    "index_name": {
      "script": {
        "lang": "painless",
        "inline": "doc[\u0027_index\u0027]" # 4
      }
    }
  }
}
'

| 1 | 查询 _index 字段 | | 2 | 聚合 _index 字段 | | 3 | 在 _index 字段上排序 | | 4 | 在脚本中访问 _index 字段 |

Copyright © Kilvn 2021. all right reserved,powered by Gitbook最后更新时间: 2021-06-08 20:22:42

results matching ""

    No results matching ""