Rati
Rati

Reputation: 45

Insert next available integer in elastic search

I am moving a table from SQL to elastic search. It has an revision_number column with value equals to previous value + 1. I found that ES does not support autoincremental feature. Should i create a static integer on server side code and assign it every time while inserting? what would be the best way to achieve it

Upvotes: 0

Views: 542

Answers (2)

Shivang MIttal
Shivang MIttal

Reputation: 1001

Using static integer will not help as when server restarts, it will be reset. There is a workaround for that by using _versions. Version number is the in-build concept of elastic search https://www.elastic.co/blog/elasticsearch-versioning-support.

Create a dummy index or type in elastic search with minimum fields. Insert a value in it with Id = 1. It will return object along with version Info. every time you need a incremental integer, update that dummy index. It will return the incremented version number. I got this trick from http://blogs.perl.org/users/clinton_gormley/2011/10/elasticsearchsequence---a-blazing-fast-ticket-server.html

Upvotes: 1

bittusarkar
bittusarkar

Reputation: 6357

Yes, Elasticsearch does not have auto-increment feature for any field. See this. As you've correctly mentioned, this has to be implemented on the client side (Client of Elasticsearch cluster) by incrementing some static integer.

Upvotes: 0

Related Questions