2

I am trying to pass a list of values to QueryBuilders.termsQuery(), but it is throwing the error:

Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [http://localhost:9200], URI [/replacement/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]

This is my java code:

Replacement linkId = null;
Replacement replacement = null;
List<Replacement> linkIDList=new ArrayList<Replacement>();
for (SearchHit hit1 : searchHits1) {
    linkId = new Replacement();
     Map<String, Object> sourceAsMap1 = hit1.getSourceAsMap();
     linkId.setLink_id((Integer) sourceAsMap1.get("link_id"));
     linkIDList.add(linkId);
}

QueryBuilder qb2 = QueryBuilders.termsQuery("id",linkIDList); // this line throws error

What is wrong with this code?

Please find the complete stacktrace

    Suppressed: org.elasticsearch.client.ResponseException: method [GET], host [http://localhost:9200], URI [/replacement/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512], status line [HTTP/1.1 400 Bad Request]
    {"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: {\n  \"terms\" : {\n    \"id\" : [\n      \"com.demo.searchengine.bean.Replacement@43262676\",\n      \"com.demo.searchengine.bean.Replacement@1c3035bc\",\n      \"com.demo.searchengine.bean.Replacement@1ae1b004\",\n      \"com.demo.searchengine.bean.Replacement@5ba72360\",\n      \"com.demo.searchengine.bean.Replacement@29c0bbf4\",\n      \"com.demo.searchengine.bean.Replacement@3440e6a5\"\n    ],\n    \"boost\" : 1.0\n  }\n}","index_uuid":"IivTlnL9QCmEUlisIilYUg","index":"replacement"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"replacement","node":"uPLyU7R5RXeirg8XzRqhnA","reason":{"type":"query_shard_exception","reason":"failed to create query: {\n  \"terms\" : {\n    \"id\" : [\n      \"com.demo.searchengine.bean.Replacement@43262676\",\n      \"com.demo.searchengine.bean.Replacement@1c3035bc\",\n      \"com.demo.searchengine.bean.Replacement@1ae1b004\",\n      \"com.demo.searchengine.bean.Replacement@5ba72360\",\n      \"com.demo.searchengine.bean.Replacement@29c0bbf4\",\n      \"com.demo.searchengine.bean.Replacement@3440e6a5\"\n    ],\n    \"boost\" : 1.0\n  }\n}","index_uuid":"IivTlnL9QCmEUlisIilYUg","index":"replacement","caused_by":{"type":"number_format_exception","reason":"For input string: \"com.demo.searchengine.bean.Replacement@43262676\""}}}]},"status":400}
2
  • Please print the complete stack trace. There must be remaining error trace after this Commented Jun 17, 2018 at 12:19
  • @Richa - i have updated with complete stack trace. Commented Jun 17, 2018 at 12:27

1 Answer 1

1

As shown in the stacktrace, it is because of the Number Format Exception. You need to send list of Integer which is the type of id field instead of passing List<Replacement> as mentioned in your code.

Instead of creating an object Of List<Replacement>, create a List and pass that list.

Hope it works for you.

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

1 Comment

Happy to Help :-)

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.