# 3.2.1.4.特定数据类型

|         分类        | 数据类型                                                                                                                                                  |
| :---------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|        IP型        | ip：描述IPv4 和 IPv6 地址                                                                                                                                   |
|   Completion补全型   | completion:提供自动完成的提示                                                                                                                                  |
| Token count 令牌计数型 | token\_count:用于统计字符串中的词条数量                                                                                                                            |
|  mapper-murmur3 型 | murmur3:计算哈希值在指数时间和并存储他们在索引中                                                                                                                          |
|   Attachment 附件型  | 查看[mapper-attachments](https://www.elastic.co/guide/en/elasticsearch/plugins/5.2/mapper-attachments.html)插件来支持索引附件，如微软Office格式，开放文档格式，EPUB，HTML等附件类型。 |
|   Percolator 抽取型  | 接受特定领域查询语言（query-dsl）的查询                                                                                                                              |

## IP型

一个ip 字段可以索引/存储IPv4和IPv6地址。

```
PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "ip_addr": {
          "type": "ip"
        }
      }
    }
  }
}

PUT my_index/my_type/1
{
  "ip_addr": "192.168.1.1"
}

GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "192.168.0.0/16"
    }
  }
}
```

IP**数据类型字段的参数**

以下是ip字段所接受的参数:

| boost            | 映射字段级查询时间提升。接受浮点数，默认值为1.0                                                                             |
| ---------------- | ----------------------------------------------------------------------------------------------------- |
| doc\_values      | 该字段是否应该按列的方式存储在磁盘上，以便以后可以用于排序、聚合或脚本编写？接受true（默认）或false。                                               |
| include\_in\_all | 字段值是否应包含在\_all字段中？ 接受true或false 。如果index设置为no ，或者如果父object字段将include\_in\_all，默认设置为false。 否则默认为true 。 |
| index            | 字段是否参数搜索，参数只接受 true (默认值) 和 false                                                                     |
| null\_value      | 接受一个配置格式的IPv4值作为替换任何显式空值的字段。 默认为null，这意味着该字段被视为丢失。                                                    |
| store            | 字段值是否应与\_source字段分开存储和检索。 接受true或false （默认）。                                                          |

**查询IP字段**

最常见的查询ip地址的方法是使用CIDR标记:`[ip_address]/[prefix_length]`. 例如:

```
GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "192.168.0.0/16"
    }
  }
}
```

或

```
GET my_index/_search
{
  "query": {
    "term": {
      "ip_addr": "2001:db8::/48"
    }
  }
}
```

## Token count 令牌计数型

类型为`token_count`的字段是一个接受字符串值的`integer`字段，对它们进行分析，然后对字符串中的token数进行索引。

例子：

```
PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "name": { # 1
          "type": "text",
          "fields": { # 2
            "length": {
              "type":     "token_count",
              "analyzer": "standard"
            }
          }
        }
      }
    }
  }
}

PUT my_index/my_type/1
{ "name": "John Smith" }

PUT my_index/my_type/2
{ "name": "Rachel Alice Williams" }

GET my_index/_search
{
  "query": {
    "term": {
      "name.length": 3  # 3
    }
  }
}
```

| [![](https://www.elastic.co/guide/en/elasticsearch/reference/current/images/icons/callouts/1.png)](https://translate.googleusercontent.com/translate_c?depth=1\&hl=zh-CN\&rurl=translate.google.com\&sl=en\&sp=nmt4\&tl=zh-CN\&u=https://www.elastic.co/guide/en/elasticsearch/reference/current/token-count.html\&usg=ALkJrhj-xw1n9gZS9tQ_tK5CUYOeTr55wA#CO186-1) | `name`字段是使用默认`standard`分析器的分析字符串字段。                                                                                                              |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [![](https://www.elastic.co/guide/en/elasticsearch/reference/current/images/icons/callouts/2.png)](https://translate.googleusercontent.com/translate_c?depth=1\&hl=zh-CN\&rurl=translate.google.com\&sl=en\&sp=nmt4\&tl=zh-CN\&u=https://www.elastic.co/guide/en/elasticsearch/reference/current/token-count.html\&usg=ALkJrhj-xw1n9gZS9tQ_tK5CUYOeTr55wA#CO186-2) | `name.length`字段是一个`token_count`[多字段](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html) ，它将在`name`字段中索引token的数量。 |
| [![](https://www.elastic.co/guide/en/elasticsearch/reference/current/images/icons/callouts/3.png)](https://translate.googleusercontent.com/translate_c?depth=1\&hl=zh-CN\&rurl=translate.google.com\&sl=en\&sp=nmt4\&tl=zh-CN\&u=https://www.elastic.co/guide/en/elasticsearch/reference/current/token-count.html\&usg=ALkJrhj-xw1n9gZS9tQ_tK5CUYOeTr55wA#CO186-3) | 此查询仅匹配包含`Rachel Alice Williams`的文档，因为它包含三个token。                                                                                                 |

> 在技术上， `token_count`类型对位置增量进行求和，而不是对token计数。这意味着即使分析仪滤除停止词，它们也包括在计数中。

## `token_count`参数 <a href="#token-shu-can-shu" id="token-shu-can-shu"></a>

`token_count`字段接受以下参数：

| [`analyzer`](https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer.html)             | 应该用于分析字符串值的[分析器](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html) 。必须值。为获得最佳性能，请使用不带token过滤器的分析器。                                                      |
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`boost`](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-boost.html)           | 映射字段级查询时间提升。接受一个浮点数，默认为`1.0` 。                                                                                                                                                       |
| [`doc_values`](https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html)         | 该字段是否应该以多列的方式存储在磁盘上，以便以后可以将其用于排序，聚合或脚本化？接受`true` （默认）或`false` 。                                                                                                                      |
| [`index`](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index.html)           | 应该可以搜索该字段吗？接受`not_analyzed` （默认）和`no` 。                                                                                                                                              |
| [`include_in_all`](https://www.elastic.co/guide/en/elasticsearch/reference/current/include-in-all.html) | 字段值是否应包含在[`_all`](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html)字段中？接受`true`或`false`默认为`false` 。注意：如果为`true` ，则将字符串值添加到\_all，而不是计算的token数量。 |
| [`null_value`](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html)         | 接受与替换任何显式`null`值的字段相同`type`的数值。默认为`null` ，这意味着该字段被视为丢失。                                                                                                                              |
| [`store`](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-store.html)           | 字段值是否应与[`_source`](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html)字段分开存储和检索。接受`true`或`false` （默认）。                                        |

## Percolator 抽取型

`percolator`字段类型将json结构解析为本地查询，并存储该查询，以便[percolate查询](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html)可以使用它来匹配提供的文档。

包含json对象的任何字段都可以配置为渗滤器字段。渗滤器字段类型没有参数设置。只需配置渗`percolator`字段类型就足以指示ES将字段视为查询。

如果以下映射配置`query`字段的`percolator`字段类型：

```
{
    "properties": {
        "query": {
            "type": "percolator"
        }
    }
}
```

那么下面的json代码段可以作为本地查询进行索引：

```
{
    "query" : {
                "match" : {
                        "field" : "value"
                }
        }
}
```

> 在渗滤型查询中引用的字段必须已经存在于与用于渗滤的索引相关联的映射中。为了确保这些字段存在，通过[创建索引](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html)或[放置映射](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) API添加或更新映射 。在渗滤型查询中引用的字段可以存在于包含`percolator`字段类型的任何类型的索引中。
>
> 此外，索引只能包含多达一个渗滤型字段映射。多个字段将被put索引拒绝并放置映射API。

### 专用渗透索引

渗滤型查询可以添加到任何索引。而不是向数据所在的索引添加渗出查询，也可以将这些查询添加到专用索引中。这样做的优点在于，这个专用的渗透索引可以有自己的索引设置（例如主分片和副本分片的数量）。如果您选择具有专门的渗透指数，则需要确保来自正常索引的映射也可在渗透指数中使用。否则，渗出查询可能会被错误解析。

### 强制未映射的字段被处理为字符串

在某些情况下，什么样的渗滤查询已经被注册了是不知道的，如果字段未映射的那些字段被渗透查询所引用，那么将添加渗滤查询失败。这意味着需要更新映射以使该字段具有适当的设置，然后可以添加渗滤查询。但是有时如果所有未映射的字段都被处理，就像这些是默认的字符串字段一样。在这种情况下，可以将`index.percolator.map_unmapped_fields_as_string`设置设置为`true` （默认为`false` ），然后如果在percolator查询中引用的字段不存在，则它将作为默认字符串字段处理，以便添加渗滤查询不会失败。

### 限制

因为`percolate`查询一次处理一个文档，它不支持针对子文件，如`has_child`和`has_parent`运行的查询和过滤器。

在查询解析过程中有许多通过调用进行获取数据的查询。例如使用`terms`查询时的术语查询，使用索引脚本时的`template`查询以及使用预索引形状时的`geo_shape` 。当这些查询由`percolator`字段类型索引时，get调用将被执行一次。因此，每次`percolator`查询评估这些查询时，将使用索引时间获取术语，形状等。如果源索引在索引时更改,需要注意的是要获取这些查询所执行的术语，每次在渗滤器查询在主分片和副本分片上进行索引时都会发生，所以实际索引的术语在分片副本之间可能不同。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/zi-duan-de-shu-ju-lei-xing/3214te-ding-shu-ju-lei-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
