Elasticsearch - IngestNode
| index.blocks.read_only | 1 true/false | 设置为 true 可使索引和索引元数据为只读,设置为 false 可允许写入和更改元数据。 |
有时我们需要在索引文档之前对其进行转换。例如,我们想从文档中删除字段或重命名字段,然后对其进行索引。这是由 Ingest 节点处理的。
集群中的每个节点都具有摄取能力,但也可以自定义为仅由特定节点处理。
涉及的步骤
摄取节点的工作涉及两个步骤 −
- 创建管道
- 创建文档
创建管道
首先创建包含处理器的管道,然后执行该管道,如下所示 −
PUT _ingest/pipeline/int-converter
{
"description": "converts the content of the seq field to an integer",
"processors" : [
{
"convert" : {
"field" : "seq",
"type": "integer"
}
}
]
}
运行上述代码,我们得到以下结果 −
{
"acknowledged" : true
}
创建文档
接下来我们使用管道转换器创建文档。
PUT /logs/_doc/1?pipeline=int-converter
{
"seq":"21",
"name":"Tutorialspoint",
"Addrs":"Hyderabad"
}
运行上述代码后,我们得到如下所示的响应 −
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
接下来我们使用 GET 命令搜索上面创建的文档,如下所示−
GET /logs/_doc/1
运行上述代码,我们得到以下结果 −
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"Addrs" : "Hyderabad",
"name" : "Tutorialspoint",
"seq" : 21
}
}
您可以看到上面 21 已成为一个整数。
不使用管道
现在我们创建一个不使用管道的文档。
PUT /logs/_doc/2
{
"seq":"11",
"name":"Tutorix",
"Addrs":"Secunderabad"
}
GET /logs/_doc/2
运行上述代码,我们得到以下结果 −
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "2",
"_version" : 1,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"seq" : "11",
"name" : "Tutorix",
"Addrs" : "Secunderabad"
}
}
从上图可以看出,11 是一个没有使用管道的字符串。

