Importing CSV File in Elasticsearch

Viewed 966

I am new to elasticsearch. Trying to import CSV file by following the guide

And successfully imported the file and it has created an index with the documents also. But what I found that in every docs _id contains random unique id as a value. I want to have value of _id from the CSV file field (the CSV file which I'm importing contains a field with unique id for every row) using query or any other ways. And I do not know how to do that. Even in docs it is not explained. A sample example of document of elasticsearch index is shown below

{
    "_index" : "sample_index",
    "_type" : "_doc",
    "_id" : "nGHXgngBpB_Kjkqcxfj",
    "_score" : 1.0,
    "_source" : {
      "categoryid" : "34128b58-9148-11eb-a8b3-0242ac130003",
      "categoryname" : "Blogs",
      "isdeleted" : "False"
    }

while adding ingest pipeline with the following query

{ "set": { "field": "_id", "value": "{{categoryid}}" } }

it throwing an error with this message

2 Answers

You can achieve this by modifying the ingest pipeline used to ingest your CSV file.

In the Ingest pipeline area (Advanced section), simply add the following processor at the end of the pipeline and the document ID will be set accordingly:

...
{
  "set": {
    "field": "_id",
    "value": "{{categoryid}}"
  }
}

It should look like this:

enter image description here

Added following processor in ingest pipeline section and it works..

{
  "processors": [
    {
      "set": {
        "field": "_id",
        "value": "{{categoryid}}"
      }
    }
  ]
}
Related