0

I have an index of a following type:

{
  company: {
    watchlist: [ {id: 1}, {id: 2}, {id, 1} ]
  }
}

In the watchlist array in the indexes, duplicate values are stored. I want the indexes not to store duplicate values as this is increasing the size of my index.

I know that i can get unique values by calling aggregation, but what I want to do here is to store unique values in the index.

I am using elasticsearch rails here, it indexes data according to the json returned from 'as_indexed_json' method. The data for the above index is in sql database, which i cannot change. I can only create indexes from that database, so i need some 'uniqueness' constraint on the field 'watchlist'.

Is there a way to do it?

Vikram Singh Jadon
  • 1,007
  • 1
  • 10
  • 23
  • How are you indexing your documents now? If your client app sends duplicate ids, ES will index them. If you don't, ES won't. – Val Sep 22 '16 at 10:58
  • I am using elasticsearch rails here, it indexes data according to the json returned from 'as_indexed_json' method. The data for the above index is in sql database, which i cannot change. I can only create indexes from that database, so i need some 'uniqueness' constraint on the field 'watchlist'. – Vikram Singh Jadon Sep 22 '16 at 11:11
  • I have added this information in the question also. – Vikram Singh Jadon Sep 22 '16 at 11:11
  • 1
    I think that's something you need to do on the rails side, maybe in `as_indexed_json`, as far as ES is concerned, it won't modify your data. – Val Sep 22 '16 at 11:16
  • Might be related to: http://stackoverflow.com/questions/21461269/how-to-create-unique-constraint-in-elasticsearch-database – Dennis Ich Sep 23 '16 at 13:58

0 Answers0