Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[es/count] failed: [illegal_argument_exception] request [/p7/_count] contains unrecognized parameter: [q] #924

Closed
koderBoy opened this issue Jan 14, 2025 · 4 comments
Labels
Area: Generator Category: Bug Something isn't working

Comments

@koderBoy
Copy link

Java API client version

8.8.2

Java version

OpenJDK Runtime Environment (Temurin)(build 1.8.0_422-b05)

Elasticsearch Version

8.8.2

Problem description

 public static void main(String[] args) throws IOException {

        HttpHost httpHost = HttpHost.create("http://127.0.0.1:9200");
        RestClientBuilder restClientBuilder = RestClient.builder(httpHost);
        restClientBuilder.setHttpClientConfigCallback(httpAsyncClientBuilder -> {
            BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "elas!@#"));
            httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
            return httpAsyncClientBuilder;
        });

        ElasticsearchClient client = new ElasticsearchClient(new RestClientTransport(restClientBuilder.build(),new JacksonJsonpMapper()));

        CountResponse count = client.count(req->req.index("p7").q("docNo:*"));
        System.out.println(count.count());
    }
@l-trotta
Copy link
Contributor

Hello, thank you for reporting this! I tested it in the newer version of the client and it looks like it's still an issue, which is weird because the json serialization of the request matches exactly what the server should accept. I'll look into this and will update soon!

@l-trotta l-trotta added Category: Bug Something isn't working Area: Generator labels Jan 14, 2025
@l-trotta
Copy link
Contributor

Found out what's happening: the server does not accept both q as a value when a body is provided, and for simplicity the java client always sends a body for POST requests, even when it's empty. Still undecided on how to fix this, in the meantime the suggested workaround it to perform the same query in the body, like this:

CountResponse count = esClient.count(req->req.index("p7")
    .query(q -> q.queryString(qs -> qs.query("docNo:*"))));

@koderBoy
Copy link
Author

Found out what's happening: the server does not accept both q as a value when a body is provided, and for simplicity the java client always sends a body for POST requests, even when it's empty. Still undecided on how to fix this, in the meantime the suggested workaround it to perform the same query in the body, like this:

CountResponse count = esClient.count(req->req.index("p7")
.query(q -> q.queryString(qs -> qs.query("docNo:*"))));

This may seem like a solution to the problem, but it feels very strange as it does not match the API description of Elastcsearch

@l-trotta
Copy link
Contributor

fixed in #926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Generator Category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants