将数千条记录同步索引到Elasticsearch中,使用Index API是否是正确的方法?

huangapple go评论67阅读模式
英文:

Indexing thousands of records into Elasticsearch using Index API synchronous is right approach?

问题

我正在尝试将超过7000条记录索引到Elasticsearch中。我将从JSon数组中选择所有这些记录,基于其长度,我将遍历数组,然后使用IndexRequest API逐一将记录索引到Elasticsearch中。由于我对Elasticsearch还不熟悉,我想确认这是否是正确的方法。我在下面提供了我的代码。

for (int i = 0; i < odsData.size(); i++) {
    IndexRequest request = new IndexRequest(ConstantsHelper.INDEX_NAME + strDate);
    request.id();
    String jsonString = odsData.get(i).toString();
    request.source(jsonString, XContentType.JSON);
    IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
}

这种方法是否正确?另外,我想在索引完成后检查数组中的记录数是否与已在Elasticsearch中索引的记录数匹配?

英文:

I am trying to index more than 7000 records into elasticsearch. I will pick all those records from JSonarray based on it's length i will loop through the array and i will index records one by one into elasticsearch using Indexrequest API. Since i am new to Elastisearch i wanted to confirm is this right approach. I have given my code below.

            for (int i = 0; i &lt; odsData.size(); i++) {
				IndexRequest request = new IndexRequest(ConstantsHelper.INDEX_NAME + strDate);
				request.id();
				String jsonString = odsData.get(i).toString();
				request.source(jsonString, XContentType.JSON);
				IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
			}

In this a right approach? Also i wanted to check No of records in array and no of records indexed in the Elasticsearch are matching once indexing gets completed?

答案1

得分: 0

没问题,这应该可以正常工作,但处理过程会比较慢。此外,还有一个批量索引的 API,可以一次性索引多个文档,速度非常快。链接

英文:

Yes that should work fine, but it will be a slow process. There is also a bulk indexing API that you can use to index multiple documents at once which is very fast. Link

huangapple
  • 本文由 发表于 2020年9月23日 20:46:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64028324.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定