KeyWord

Keyword datatype

用于索引结构化的数据的字段,比如 email 地址、主机名、状态码、邮政编码或者标签,通常用于过滤(查找所有状态是 published 的博客文章)、排序、聚合。keyword字段只能通过精确值来搜索。

如果需要索引全文内容,比如 email 体或者产品描述,那么你可能需要使用 text字段。

curl -XPUT 'localhost:9200/my_index?pretty' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "tags": {
          "type":  "keyword"
        }
      }
    }
  }
}'

Parameters for keyword fields

keyword 字段接受的参数

| boost | Mapping field-level query time boosting. Accepts a floating point number, defaults to 1.0. | | doc_values | Should the field be stored on disk in a column-stride fashion, so that it can later be used for sorting, aggregations, or scripting? Accepts true(default) or false. | | eager_global_ordinals |  Should global ordinals be loaded eagerly on refresh? Accepts true or false (default). Enabling this is a good idea on fields that are frequently used for terms aggregations. | | fields | Multi-fields allow the same string value to be indexed in multiple ways for different purposes, such as one field for search and a multi-field for sorting and aggregations. | | ignore_above | Do not index any string longer than this value. Defaults to 2147483647 so that all values would be accepted. | | include_in_all | Whether or not the field value should be included in the _all field? Accepts true or false. Defaults to false if index is set to no, or if a parent object field sets include_in_all to false. Otherwise defaults to true. | | index | Should the field be searchable? Accepts true (default) or false. | | index_options | What information should be stored in the index, for scoring purposes. Defaults to docs but can also be set to freqs to take term frequency into account when computing scores. | | norms | Whether field-length should be taken into account when scoring queries. Accepts true or false (default). | | null_value | Accepts a string value which is substituted for any explicit null values. Defaults to null, which means the field is treated as missing. | | store | Whether the field value should be stored and retrievable separately from the _source field. Accepts true or false (default). | | similarity | Which scoring algorithm or similarity should be used. Defaults to BM25. | | normalizer | [experimental]  This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.How to pre-process the keyword prior to indexing. Defaults to null, meaning the keyword is kept as-is. |

注意

2.x版本导入的索引不支持 keyword 。它们会尝试将 keyword 降级到 string 。这允许你将新映射和旧映射合并。长期索引在升级到6.x之前必须重新创建,但是映射降级允许你根据自己的安排来进行重新创建。