【问题标题】:Fetching Index data from elasticsearch DB using Spring Data ElasticSearch使用 Spring Data ElasticSearch 从 elasticsearch DB 获取索引数据
【发布时间】:2021-12-24 07:51:41
【问题描述】:

我有一个 java 代码,它使用 Spring-data-elasticsearch 连接到 Elasticsearch DB,并通过连接到存储库并执行 findAll() 方法来获取所有索引数据。从 ES 接收的数据正在由单独的应用程序处理。当新数据插入弹性搜索时,我有以下查询

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.  

我不想再次执行 findAll() 方法。因为它返回整个数据(也包括之前处理的记录)。

非常感谢您对此的任何帮助。

【问题讨论】:

    标签: elasticsearch kibana spring-data-elasticsearch


    【解决方案1】:

    当您的应用程序插入 Elasticsearch 时,您将需要向包含时间戳的实体添加一个字段(我在这里称之为 createdAt)。一种可能性是使用 Spring Data Elasticsearch 的the auditing support 自动设置值,或者您在应用程序中设置值。如果数据是由其他应用程序插入的,您需要确保它包含时间戳,其格式与您的应用程序中该字段的字段类型定义相映射。

    然后您需要在存储库中定义一个方法,例如

    SearchHits<T> findByCreatedAtAfter(Timestamp referenceValue);
    

    关于在插入新数据时以某种形式收到通知:我不知道 Elasticsearch 提供了类似的功能。您可能需要定期调用检索数据的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 2016-05-12
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多