0

I want to update all the documents that have for exemple the same name. I've seen in the elasticsearch documentation that I can use _update_by_query. So I tried to implement it in my repository like this:

@Query("{\"script\": { \"inline\": \"ctx._source.name = ?1\"; \"ctx._source.username = ?2\"; \"ctx._source.avatar = ?3\", \"lang\": \"painless\" }, \"query\": { \"match\": { \"name\" : \"?1\" }}")
List<User> update(String name, String username, String avatar);

But I get the following error:

nested exception is ElasticsearchStatusException[Elasticsearch exception [type=parsing_exception, reason=[script] query does not support [inline]]]
    at org.springframework.kafka.listener.SeekUtils.seekOrRecover(SeekUtils.java:157) ~[spring-kafka-2.5.0.RELEASE.jar:2.5.0.RELEASE]
0

2 Answers 2

1

Edit 26.06.2020:

This answer is not correct, I added a correct on.

Old incorrect answer:

Seems strange to me, that this error comes from org.springframework.kafka.listener.SeekUtils.

To update using a script, you can use the update(UpdateQuery updateQuery, IndexCoordinates index) of a ElasticsearchOperations instance.

To have this in your Repository, you will need to create a repository cusomization like it is described here. In the implementation, autowire a ElasticsearchOperations instance. In this custom repository interface, you define the method

List<User> update(String name, String username, String avatar);

In the implementation, build up a UpdateQuery object with the script and the other information and pass this to the ElasticsearchOperations instance.

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

2 Comments

Can you please share examples on how to use ElasticsearchOperations
please check my other answer
0

After checking the code of Spring Data Elasticsearch, I need to withdraw what I wrote in the first answer:

Currently Spring Data Elasticsearch does not support update by query. It is only possible to update entities with a know id either in a single operation or in a batch update.

I created an issue in Jira to add support for that.

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.