0

I want to expose flexible REST service which allows client to perform any query. Similar to elasticsearch API:

http://localhost:9200/blog/post/_search?q=user:dilbert

I found ElasticsearchTemplate and it's method queryForList(StringQuery query, Class clazz). It seems to fit for my purpose.

@RequestMapping(value = "/search", method = RequestMethod.GET)
public List<DynamicEntity> findAllBySearch(@RequestParam("query") String query) {
    return elasticsearchTemplate.queryForList(new StringQuery(query), DynamicEntity.class);
}

But I don't know how to construct the query. I wasn't able to find documentation on this. I tried to guess it with no success. For example:

http://localhost:8080/dynamic/search?query={"query":{"className":"invoice"}}

className is an attribute of DynamicEntity.

I get following error:

org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [dfs], all shards failed; shardFailures {[feu_3VGkTgKKUziW19mXUQ][dynamic][3]: SearchParseException[[dynamic][3]: from[0],size[10]: Parse Failure [Failed to parse source [{"from":0,"size":10,"query_binary":"eyJxdWVyeSI6eyJjbGFzc05hbWUiOiJpbnZvaWNlIn19"}]]]; nested: QueryParsingException[[dynamic] No query registered for [query]]; }{[feu_3VGkTgKKUziW19mXUQ][dynamic][4]: SearchParseException[[dynamic][4]: from[0],size[10]: Parse Failure [Failed to parse source [{"from":0,"size":10,"query_binary":"eyJxdWVyeSI6eyJjbGFzc05hbWUiOiJpbnZvaWNlIn19"}]]]; nested: QueryParsingException[[dynamic] No query registered for [query]]; }{[feu_3VGkTgKKUziW19mXUQ][dynamic][1]: SearchParseException[[dynamic][1]: from[0],size[10]: Parse Failure [Failed to parse source [{"from":0,"size":10,"query_binary":"eyJxdWVyeSI6eyJjbGFzc05hbWUiOiJpbnZvaWNlIn19"}]]]; nested: QueryParsingException[[dynamic] No query registered for [query]]; }{[feu_3VGkTgKKUziW19mXUQ][dynamic][2]: SearchParseException[[dynamic][2]: from[0],size[10]: Parse Failure [Failed to parse source [{"from":0,"size":10,"query_binary":"eyJxdWVyeSI6eyJjbGFzc05hbWUiOiJpbnZvaWNlIn19"}]]]; nested: QueryParsingException[[dynamic] No query registered for [query]]; }{[feu_3VGkTgKKUziW19mXUQ][dynamic][0]: SearchParseException[[dynamic][0]: from[0],size[10]: Parse Failure [Failed to parse source [{"from":0,"size":10,"query_binary":"eyJxdWVyeSI6eyJjbGFzc05hbWUiOiJpbnZvaWNlIn19"}]]]; nested: QueryParsingException[[dynamic] No query registered for [query]]; }

Im I using right method? How to construct valid query? I don't want to use any builder classes because the query should be constructed on client in JavaScript.

2
  • 1
    Your sample query is not valid (i.e. No query registered for [query]), can you try query={"term":{"className":"invoice"}} instead (i.e. using term instead of query)? Commented Oct 27, 2015 at 6:29
  • It worked! Thank you very much. Do you want to put this as an answer for the question? Commented Oct 27, 2015 at 6:43

1 Answer 1

2

According to the error you posted, your sample query is not valid (i.e. No query registered for [query]).

You should use this instead (i.e. using term instead of query):

query={"term":{"className":"invoice"}}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.