英文:
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 < 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论