简体   繁体   English

使用 Spring Data ElasticSearch 从 elasticsearch DB 中获取索引数据

[英]Fetching Index data from elasticsearch DB using Spring Data ElasticSearch

I have a java code which connects to Elasticsearch DB using Spring-data-elasticsearch and fetches all the index data by connecting to the repository and executing the findAll() method.我有一个 java 代码,它使用 Spring-data-elasticsearch 连接到 Elasticsearch DB,并通过连接到存储库并执行 findAll() 方法来获取所有索引数据。 The data received from ES is being processed by a seperate application.从 ES 接收的数据正在由单独的应用程序处理。 When new data is inserted into elastic search, I have the below queries当新数据插入弹性搜索时,我有以下查询

1. How can I fetch only the newly inserted data Programatically ?
2. Apart from using the DSL queries, Is there a way to Asyncronously get the new records as and when new data is inserted into elasticsearch DB.  

I dont want to execute the findAll() method again.我不想再次执行 findAll() 方法。 Because it returns the entire data ( including the previously processed records as well) .因为它返回整个数据(也包括之前处理的记录)。

Any help on this is much appreciated.非常感谢您对此的任何帮助。

You will need to add a field (I call it createdAt here) to your entities that contains the timestamp when your application inserts into Elasticsearch.您将需要一个字段(我称之为添加createdAt这里)你的实体包含时间戳当你的应用程序插入到Elasticsearch。 One possibility would be to use the auditing support of Spring Data Elasticsearch to have the value set automatically, or you set the value in your application.一种可能性是使用 Spring Data Elasticsearch 的审计支持来自动设置该值,或者您在应用程序中设置该值。 If the data is inserted by some other application you need to make sure that it contains a timestamp in a format that maps the field type definition of this field in your application.如果数据是由某个其他应用程序插入的,您需要确保它包含一个时间戳,其格式与您的应用程序中该字段的字段类型定义相映射。

Then you'd need to define a method in your repository like然后你需要在你的存储库中定义一个方法,比如

SearchHits<T> findByCreatedAtAfter(Timestamp referenceValue);

As for getting a notification in some form when new data is inserted: I'm not aware that Elasticsearch offers something like that.至于在插入新数据时以某种形式收到通知:我不知道 Elasticsearch 提供类似的东西。 You will probably need to regularly call the method that retrieves the data.您可能需要定期调用检索数据的方法。

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

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