Question on ingesting multiple csv files with repeated data

Hi, does elastic auto remove duplicated data when i ingest multiple csv files with repeated data in them. or is there a way to enable the removal?


Only if you are using the same _id in which case the duplicated row will overwrite the previous one.

ohhh i see. thanks for the prompt reply @dadoonet :bowing_man:
how do I go about setting the id for the ingest? the data i have is sth like


The way i am ingesting the data right now looks sth like this, but as per your suggestion, I am not sure on where to set the id, and how to go about doing it. and if the amount of data (in rows) is inconsistent, will the id be able to track that the particular row is repeated?

for x in sorted(files):
    with open(x) as f:
        reader = csv.DictReader(f)
        helpers.bulk(es, reader, index='testindex')

Just found an article on enrich policy with ingest processor,

Is it something like this?

If you don't define an _id, then elasticsearch will generate one for you.
If the unique id in your case is the date of the event, then you can think of using the date as the _id.

So CSV1 will be like:

PUT index/_doc/2020-04-19
{ "date": "2020-04-19", ... }
PUT index/_doc/2020-04-20
{ "date": "2020-04-20", ... }

Then the second CSV will be something like:

PUT index/_doc/2020-04-20
{ "date": "2020-04-20", ... }
PUT index/_doc/2020-04-21
{ "date": "2020-04-21", ... }

Which means that at the end, you will have the following records:

{ "date": "2020-04-19", ... }
{ "date": "2020-04-20", ... }
{ "date": "2020-04-21", ... }

Thanks for the information! I think i got the solution for the _id for my case already.

p.put_pipeline(id='attachment', body={
    'description': 'setting press release date to _id',
    'processors': [
            "set": {
                "field": "_id",
                "value": "{{Press release date}}"

Yes. That will work.

Out of curiosity, why not providing the correct _id in your Python script instead of having to reprocess the json in an ingest pipeline?
It will be faster if you do that on Python side.

haha, i guess there will always be a better way to work things out, but i think for now i will leave it as it is, i will update it if there is a need to. thanks anyways!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.