Elasticsearch 简明教程

Elasticsearch - IngestNode

index.blocks.read_only

1 true/false

Set to true to make the index and index metadata read only, false to allow writes and metadata changes.

有时,我们需要在索引文档之前对其进行转换。例如,我们希望从文档中删除一个字段或重命名一个字段,然后进行索引。这由摄取节点处理。

Sometimes we need to transform a document before we index it. For instance, we want to remove a field from the document or rename a field and then index it. This is handled by Ingest node.

群集中每个节点都有摄取功能,但也可以将其自定义为仅由特定节点处理。

Every node in the cluster has the ability to ingest but it can also be customized to be processed only by specific nodes.

Steps Involved

摄取节点的工作涉及两个步骤 −

There are two steps involved in the working of the ingest node −

  1. Creating a pipeline

  2. Creating a doc

Create a Pipeline

首先创建包含处理器的管道,然后执行管道,如下所示 −

First creating a pipeline which contains the processors and then executing the pipeline, as shown below −

PUT _ingest/pipeline/int-converter
{
   "description": "converts the content of the seq field to an integer",
   "processors" : [
      {
         "convert" : {
            "field" : "seq",
            "type": "integer"
         }
      }
   ]
}

运行以上代码时,我们得到以下结果:-

On running the above code, we get the following result −

{
   "acknowledged" : true
}

Create a Doc

接下来,使用管道转换器创建文档。

Next we create a document using the pipeline converter.

PUT /logs/_doc/1?pipeline=int-converter
{
   "seq":"21",
   "name":"Tutorialspoint",
   "Addrs":"Hyderabad"
}

在运行以上代码时,我们得到响应,如下所示:-

On running the above code, we get the response as shown below −

{
   "_index" : "logs",
   "_type" : "_doc",
   "_id" : "1",
   "_version" : 1,
   "result" : "created",
   "_shards" : {
      "total" : 2,
      "successful" : 1,
      "failed" : 0
   },
   "_seq_no" : 0,
   "_primary_term" : 1
}

接下来,我们使用 GET 命令搜索以上创建的文档,如下所示:-

Next we search for the doc created above by using the GET command as shown below −

GET /logs/_doc/1

运行以上代码时,我们得到以下结果:-

On running the above code, we get the following result −

{
   "_index" : "logs",
   "_type" : "_doc",
   "_id" : "1",
   "_version" : 1,
   "_seq_no" : 0,
   "_primary_term" : 1,
   "found" : true,
   "_source" : {
      "Addrs" : "Hyderabad",
      "name" : "Tutorialspoint",
      "seq" : 21
   }
}

您可以在上面看到,21 已经变成一个整数。

You can see above that 21 has become an integer.

Without Pipeline

现在,我们不用管道创建文档。

Now we create a document without using the pipeline.

PUT /logs/_doc/2
{
   "seq":"11",
   "name":"Tutorix",
   "Addrs":"Secunderabad"
}
GET /logs/_doc/2

运行以上代码时,我们得到以下结果:-

On running the above code, we get the following result −

{
   "_index" : "logs",
   "_type" : "_doc",
   "_id" : "2",
   "_version" : 1,
   "_seq_no" : 1,
   "_primary_term" : 1,
   "found" : true,
   "_source" : {
      "seq" : "11",
      "name" : "Tutorix",
      "Addrs" : "Secunderabad"
   }
}

您可以在上面看到,11 是一个字符串,没有使用管道。

You can see above that 11 is a string without the pipeline being used.