1

We were doing bullk insert by using bulkIndex as follow:

List<IndexQuery> indexQueries = new ArrayList<>();
        for (FooDocument fooDocument : fooDocuments) {
            IndexQuery query = new IndexQueryBuilder()
                    .withId(String.valueOf(fooDocument.getId()))
                    .withObject(fooDocument)
                    .build();
            indexQueries.add(query);
        }
    elasticsearchOperations.bulkIndex(indexQueries, IndexCoordinates.of("foo_index_3"));

We also want to use for bulk updates something like:

elasticsearchOperations.bulkUpdate(updateQueries, IndexCoordinates.of("foo_index_3"));

But bulkUpdate requires list of UpdateQuery.I am trying to create it by doing something like:

List<IndexQuery> updateQueries = new ArrayList<>();
        for (FooDocument fooDocument : fooDocuments) {
            UpdateQuery updateQuery = new UpdateQueryBuilder()//which Builder class and method is required?
                    .withId(String.valueOf(fooDocument.getId()))
                    .withObject(fooDocument)
                    .build();
            updateQueries.add(query);
        }

But unlike IndexQueryBuilder there is no UpdateQueryBuilder() available, what is the correct way to build the UpdateQuery and which Builder class should we use? I am wondering whether UpdateQueryBuilder class has been deprecated.

P.S: we are using 4.0.2.RELEASE version of spring-data-elasticsearch

8
  • Have you tried UpdateQuery.Builder() ? Commented Nov 19, 2020 at 14:37
  • @Val, I am not aware about how to build it using it, all I have is id and Document as in IndexyQuery, was wondering whether same is possible with UpdateQuery, If you could provide the sample, that would be really helpful. Commented Nov 19, 2020 at 14:42
  • Are you updating all fields of the document or just a few? Commented Nov 19, 2020 at 14:43
  • @Val, we are using it for insertion, kinda updating like all fields, due to some reason, cannot use bulkIndex Commented Nov 19, 2020 at 14:50
  • Since you're updating all fields, why don't you simply reindex the document with IndexQuery instead? Commented Nov 19, 2020 at 14:52

1 Answer 1

2

You create an UpdateQuery with a builder like this:

UpdateQuerybuilder builder = UpdateQuery.builder(id)
   .with(...)
   .build();

Here the builder is a nested class and not a separate one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.