简体   繁体   English

如何在弹性搜索中创建具有相同ID的不同文档

[英]How to create different documents in elastic search but same ID

Suppose I have 10 instances of an object that has some fields. 假设我有一个包含一些字段的对象的10个实例。 One of the field specify the ID. 字段之一指定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. 在这10个实例中,ID保持不变,但是与日期时间和位置相关的字段发生了变化。

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. 但是您可以观察到id保持不变,只是位置和时间发生了变化。

Using java, spring-data-elasticsearch i am able to put the information in elastic search. 使用java,spring-data-elasticsearch我可以将信息放入弹性搜索中。

The problem that i face is that in elastic search the total number of documents that are created is 1. 我面临的问题是在弹性搜索中创建的文档总数为1。

First a document with id as 123 is created and then that document is updated 9 times. 首先创建ID为123的文档,然后将该文档更新9次。 So the final document has _version as 10. 因此,最终文档的_version为10。

How can i create 10 different documents in elastic search with same id. 如何在具有相同ID的弹性搜索中创建10个不同的文档。

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. 如果这些字段将出现在同一个类中,那么我可以使用这些字段来生成哈希码,以便生成唯一的具有代码的代码,从而将其用于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. 请有人建议我如何创建不同的文档...或单个文档,但是在弹性搜索中有10个子实例。

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. _id字段每个文档都有一个_id来唯一标识它,并对其进行了索引,以便可以使用GET API或ids查询来查找文档。

Spring will map id in class to _id in elasticsearch document. Spring会将class中的id映射到elasticsearch文档中的_id。

_id in elasticsearch plays very specific role and can not accommodate discribed functionality. elasticsearch中的_id扮演非常具体的角色,不能容纳描述的功能。 I would suggest you to use different field name like InstanceId . 我建议您使用不同的字段名称,例如InstanceId In this case it will be possible to have same value in different documents. 在这种情况下,在不同的文档中可能具有相同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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