【问题标题】:Elastic Search full importElastic Search 完全导入
【发布时间】:2015-05-05 13:55:35
【问题描述】:

我们在项目中使用 Elastic Search,并遵循推送方法。 我们有一个调度程序,每 30 分钟运行一次,从表中读取数据并使用 Spring Data Elastic Search 将其推送到 Elastic Search。

Collection<ElasticSearchIndexObj> indexObjs = new ArrayList<>();

Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            conn = dataSource.getConnection();

            stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
            stmt.setFetchSize(FETCH_SIZE);          
            rs =  stmt.executeQuery(ESEARCH_FULL_IMPORT_QUERY);

            int i=1;
            while (rs.next()) {
                ElasticSearchIndexObj indexObj = new ElasticSearchIndexObj();
                indexObj.setName("Raja");


                indexObjs .add(indexObj);

                if (i % FETCH_SIZE == 0) {
                    elasticSearchObjIndexRepository.save(indexObjs);
                    indexObjs.clear();
                }               
                i=i+1;
            }           
            elasticSearchSecurityIndexRepository.save(indexObjs);
            indexObjs.clear();

我们确实每 30 分钟读取整个表并插入到弹性搜索中,以保持索引数据与表同步。该表由其他团队拥有。

怀疑:- 行已从表中删除。现在,当我选择 * 时,我不会得到已删除的记录。但是,这些记录仍然存在于弹性搜索中,这些记录将成为搜索中的陈旧数据。如何在作为计划的一部分插入之前删除弹性搜索中的所有记录而不影响前屏幕中的搜索。

无论如何我可以在这里使用事务,以便我将全部删除,保存并最终提交。

谢谢, 巴斯卡尔.S

【问题讨论】:

    标签: elasticsearch spring-data


    【解决方案1】:

    您可以使用弹性搜索的删除 API 删除索引。

    $ curl -XDELETE 'http://localhost:9200/index_name
    

    要删除所有索引,您可以使用 * 或 _all。
    为了在 java 中使用相同的东西,你必须执行这个查询

    DeleteResponse response = client.prepareDelete().execute().actionGet();  
    

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2022-09-29
      • 2021-03-18
      • 1970-01-01
      相关资源
      最近更新 更多