Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing CSV File in Elasticsearch

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

like image 786
md samual Avatar asked Mar 18 '26 08:03

md samual


1 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

like image 82
Val Avatar answered Mar 20 '26 19:03

Val