0

I am trying to execute a URI based query like below. But i don't see any effect of the search parameters i am passing. And also i want to disable _source=false. Can you help me with the query. I am using java to perform the same using Java.net packages. This query return everything no matter what search parameter i pass.

URI: "http://localhost:9200/twitter/twitter/_search?updatedBy=XX&node=YY"

Java Code:

   String charset = "UTF-8"; 
            String updatedBy = "XX";
            String node = "YY";

    String query = String.format("updatedBy:%s&nodeId:%s",
            URLEncoder.encode(updatedBy, charset),
            URLEncoder.encode(nodeId, charset));
    System.out.println(searchEsUrl + "?q=" + query);

    URLConnection connection = new URL(searchEsUrl + "?q=" + query).openConnection();
    connection.setRequestProperty("Accept-Charset", charset);

1 Answer 1

1

Try this instead

String query = String.format("updatedBy:%s+AND+nodeId:%s",
        URLEncoder.encode(updatedBy, charset),
        URLEncoder.encode(nodeId, charset));
URLConnection connection = new URL(searchEsUrl + "?_source=false&q=" + query).openConnection();

The issue was that whatever is sent in the q= parameter needs to follow the query string query syntax rules and two constraints are ANDed using the AND operator not & like this: updatedBy:XX AND nodeId:YY

The URI you want to construct is thus:

"http://localhost:9200/twitter/twitter/_search?q=updatedBy:XX AND nodeId:YY"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick reply. This works perfectly fine. As you mentioned i was using "&" instead of AND.
It works fine now. I am even able to disable the source as well as pass size parameter. I have accepted it as an answer.

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.