Custom query Parser in Search Api


I have a custom query parser and I can query my Index using Sense as follows:

GET myIndex/_search
"query": {
"query" : "blabla"
My question is, how can I parse the query with myParser in Search Api? How do I mention Parser in QueryBuilders?

(Isabel Drost-Fromm) #2

What exactly do you mean here? I'm guessing you want to use your "myParser" class from the Java API. What version of ES are you using?

Depending on whether you are on ES 2.x or 5.x what you need to implement is "slightly" different.



@mainec Thank you for your answer.
I'm relatively new to elasticsearch, so please bear with me :slight_smile:

I use ES 2.x

I installed the new parser plugin to my ES, and I thought, if I can use it via Sense, then I can do the same when I use Search Api. Like, building query, and mention there somehow, that you want to parse this query with myParser.


(Isabel Drost-Fromm) #4

The one you wrote I suppose? Did you follow any documentation in particular when doing so?

You thought you can use it via Sense or you actually tried out using it via Sense?

Again - to be clear, you mean the Java Search API here? Or do you mean something else?



@mainec The plugin is is written by my collegue. and I have the source code as well.
I used it via Sense, and it works.
Yes, I mean Java Search Api.

(Isabel Drost-Fromm) #6

I believe what you are missing is implementing a QueryBuilder. No need to actually put that into the QueryBuilders class, you can create instances for that from your application code.

The important part that this QueryBuilder will need is a toXContent method. Checkout the other QueryBuilder implementations in the Elasticsearch code base for examples.

One warning: This infrastructure changes substantially when switching to 5.0.


I just used setSource and just put my query in json format.

    SearchResponse response = client.prepareSearch("myIndex")

and it seems to work now.

(system) #8

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