# include\_in\_all（\_all 查询包含字段）

**include\_in\_all**参数用于控&#x5236;**\_all**查询时需要包含的字段.默认为**true**，除非在**index**设置成**no。**

以下示例如何将**data**字段&#x4ECE;**\_all**查询中剔除 ：

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "title": { #1
          "type": "text"
        },
        "content": { #2
          "type": "text"
        },
        "date": { #3
          "type": "date",
          "include_in_all": false
        }
      }
    }
  }
}
'
```

| 1 , 2 | **title**字段和**content**字段将包含&#x5728;**\_all**查询中。 |
| ----- | ------------------------------------------------- |
| 3     | **date**字段将不包含&#x5728;**\_all**查询中。               |

> 注意:**include\_in\_all**可以在同一个索引的同一个字段作不同的设置.可以使用[**PUT mapping API**](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-put-mapping.html)相同字段名修改参数值。

**include\_in\_all** 参数也可作用于**type**（类型）、文档或者嵌套字段，这样该作用域下的所有字段将继承该属性。例如：

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "include_in_all": false, #1
      "properties": {
        "title":          { "type": "text" },
        "author": {
          "include_in_all": true, #2
          "properties": {
            "first_name": { "type": "text" },
            "last_name":  { "type": "text" }
          }
        },
        "editor": {
          "properties": {
            "first_name": { "type": "text" }, #3
            "last_name":  { "type": "text", "include_in_all": true } #4
          }
        }
      }
    }
  }
}
'
```

| 1    | **my\_type**下的所有字段将不包含&#x5728;**\_all**查询中。                                                                          |
| ---- | -------------------------------------------------------------------------------------------------------------------- |
| 2    | **author.first\_name**和 **author.last\_name**将包含&#x5728;**\_all**查询中。                                                |
| 3, 4 | 只有 **editor.last\_name**字段包含&#x5728;**\_all**查询中。**editor.first\_name**字段由于继承**type**（类型）属性将不包含&#x5728;**\_all**查询中。 |

> 备注:
>
> **Multi-fields**和 **include\_in\_all**
>
> **\_all**查询加入的是原始字段,而不是作用在字段分词产生的**terms**上。因此，在[**multi-fields**](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/multi-fields.html) 上设置**include\_in\_all**为**true**将毫无意义，因为每一个 **multi-field**将继承父字段而拥有相同的参数值。
