Unknown key for a START_OBJECT in [queryBuilder]

Hello Gurus, I am relatively new to the group. I am posting the below query via JAVA API and seeing error as follows. Not sure what i am missing.

Request Body : {"query":{"match_all":{"boost":1.0}}}

Error response:

{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [queryBuilder].","line":1,"col":17}],"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [queryBuilder].","line":1,"col":17},"status":400}

At the same time if use the same request body in postman, the same works fine.

MatchAllQueryBuilder queryBuilder = QueryBuilders.matchAllQuery();

  SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
  SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList());
  try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
        .createParser(new NamedXContentRegistry(searchModule.getNamedXContents()), searchSourceBuilder.toString())) {

I am using SearchSourceBuilder to build a match_all query and passing the same as part of the request. Please let me know in case of more details needed.

Why are you calling SearchModule?

This should be fine:

SearchRequest searchRequest = new SearchRequest(); 
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 
SearchResponse searchResponse = client.search(searchRequest);

Thanks for the reply @dadoonet, I am not using client , we have our own implementation of service call. Tied the above and i see below error.

{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a VALUE_NULL in [remoteAddress].","line":1,"col":18}],"type":"parsing_exception","reason":"Unknown key for a VALUE_NULL in [remoteAddress].","line":1,"col":18},"status":400}

I believe SearchRequest is suitable for the Client based request. I am wondering on what to use when custom rest implementation is used (Like cxf, jersey..etc)

I just need to create a body with json data and invoke the service. Hope this helps.

Would that work?

    SearchSourceBuilder sb = new SearchSourceBuilder();
    String json = sb.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).string();

Hey David, Thanks for the information. It worked.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.