简体   繁体   中英

How to create different documents in elastic search but same ID

Suppose I have 10 instances of an object that has some fields. One of the field specify the ID. Two other fields have data regarding the location (latitude and longitude). One field has date time information.

In these 10 instances say the ID remains the same but fields related to date time and location changes.

Instance1 = id - 123; lat - 58.00; lon - 16.00; date - 2017-07-11 12:19:00
Instance1 = id - 123; lat - 60.00; lon - 17.00; date - 2017-07-11 12:29:00
Instance1 = id - 123; lat - 62.00; lon - 18.00; date - 2017-07-11 12:39:00
Instance1 = id - 123; lat - 64.00; lon - 19.00; date - 2017-07-11 12:49:00
Instance1 = id - 123; lat - 66.00; lon - 20.00; date - 2017-07-11 12:59:00

The above data is dummy data. But you can observe that id remains the same, just position and time changes.

Using java, spring-data-elasticsearch i am able to put the information in elastic search.

The problem that i face is that in elastic search the total number of documents that are created is 1.

First a document with id as 123 is created and then that document is updated 9 times. So the final document has _version as 10.

How can i create 10 different documents in elastic search with same id.

Another thing to note is that these fields are not present in same class, the actual data object is quite complex, but as a whole the data object will have these fields. Also the data object can have different type of instances but these fields will be present.

If these fields would have been present in a same class then i could have used the fields for generating hashcode, so that a unique has code is generated and thus be used for ID.

Please can someone suggest how can i achieve in creating different documents...or a single document but having 10 sub instances in elastic search.

Thanks

from documentation

_id field Each document has an _id that uniquely identifies it, which is indexed so that documents can be looked up either with the GET API or the ids query.

Spring will map id in class to _id in elasticsearch document.

_id in elasticsearch plays very specific role and can not accommodate discribed functionality. I would suggest you to use different field name like InstanceId . In this case it will be possible to have same value in different documents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM