include_in_all(_all 查询包含字段)

include_in_all 参数用于控制 _all 查询时需要包含的字段.默认为 true,除非在 index 设置成 no。

以下示例如何将 data 字段从 _all 查询中剔除 :

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "properties": {
  6. "title": { #1
  7. "type": "text"
  8. },
  9. "content": { #2
  10. "type": "text"
  11. },
  12. "date": { #3
  13. "type": "date",
  14. "include_in_all": false
  15. }
  16. }
  17. }
  18. }
  19. }
  20. '

| 1 2 | title 字段和 content 字段将包含在 _all 查询中。 | | 3 | date 字段将不包含在 _all 查询中。 |

注意

include_in_all 可以在同一个索引的同一个字段作不同的设置.可以使用 PUT mapping API 相同字段名修改参数值。

include_in_all 参数也可作用于type(类型)、文档或者嵌套字段,这样该作用域下的所有字段将继承该属性。例如:

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "include_in_all": false, #1
  6. "properties": {
  7. "title": { "type": "text" },
  8. "author": {
  9. "include_in_all": true, #2
  10. "properties": {
  11. "first_name": { "type": "text" },
  12. "last_name": { "type": "text" }
  13. }
  14. },
  15. "editor": {
  16. "properties": {
  17. "first_name": { "type": "text" }, #3
  18. "last_name": { "type": "text", "include_in_all": true } #4
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }
  25. '

| 1 | my_type 下的所有字段将不包含在 _all 查询中。 | | 2 | author.first_nameauthor.last_name 将包含在 _all 查询中。 | | 3 4 | 只有 editor.last_name 字段包含在 _all 查询中。editor.first_name 字段由于继承 type(类型)属性将不包含在 _all 查询中。 |

备注

Multi-fieldsinclude_in_all

_all 查询加入的是原始字段,而不是作用在字段分词产生的 terms 上。因此,在 multi-fields 上设置include_in_alltrue 将毫无意义,因为每一个 multi-field 将继承父字段而拥有相同的参数值。

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

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

贡献者 : 郭峰ApacheCNApache中文网