1. store(存储)

默认情况下,字段值会被索引使他们能搜索,但他们不会被 stored(存储)。意思就是这个字段能查询,但不能取回他的原始值。

但这没有关系。这个字段值已经是 **[_source](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-source-field.html "_source field") **字段的一部分,他是被默认存储的。如果你只想取回一个字段或者少部分字段的值,而不是整个 **[_source](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-source-field.html "_source field")**,可以通过 **[source filtering](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-request-source-filtering.html "Source filtering")** 达到目的。

在这种情况下可以有意识的去 store(存储)一个字段。例如,你有一个包含title(标题), date(时间)和一个很大的 content(内容)字段,你仅仅只想取回 titledate ,而不需要从整个 _source字段提取内容:

curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "title": {
          "type": "text",
          "store": true #1
        },
        "date": {
          "type": "date",
          "store": true #2
        },
        "content": {
          "type": "text"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "title":   "Some short title",
  "date":    "2015-01-01",
  "content": "A very long content field..."
}
'
curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "stored_fields": [ "title", "date" ] #3
}
'

| 1 2 | titledate 字段将被存储。 | | 3 | 这个请求将返回 titledate 的值。 |

备注

存储的字段将作为数组返回

为了保持一致性,存储的字段将总是作为数据返回,因为没有办法知道原始字段是单个值、多值还是空数组。

如果你需要原始值,你应该从 _source字段返回。

另一种情况存储字段,是存在没有存入 _source的字段(例如 **[copy_to](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/copy-to.html "copy_to") **字段)。

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-store.html(修改该链接为官网对应的链接)

译文链接 : http://www.apache.wiki/pages/viewpage.action?pageId=10027606(修改该链接为 ApacheCN 对应的译文链接)

贡献者 : 郭峰ApacheCNApache中文网

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

results matching ""

    No results matching ""