Elasticsearch Jest client add condition to json query using parser


(GBP) #1

I am using Elasticsearch 6.3 with Jest client 6.3 (Java API)

Search search = new Search.Builder(jsonQueryString)
                    .addIndex("SOME_INDEX")
                    .build();
SearchResult result = jestClient.execute(search);

And this is my sample JSON query

{
"query": {
    "bool" : {
        "filter": {
            "match" :{ 
                "someField" : "some value" 
                }
            }
        }
    }
}

The JSON query string is accepted as a POST request body and then passed to the Jest client. Before I can execute the json query on the Jest client, I need to add conditions to the query (programmatically) for e.g.

{
"query": {
    "bool" : {
        "filter": {
            "match" :{ 
                "someField" : "some value" 
                }
            }
        },
        "must": {
            "match" :{ 
                "systemField" : "pre-defined value" 
                }
            }
        }
    }
}

Is there an API that allows to parse the JSON query and add conditions to it before it can be executed on Jest client? The JSON query can be any query supported by Query DSL and not necessarily contain bool condition (i.e. it can contain sort, aggregations etc). I need to add a pre-defined condition to the query. Nearest I got to the solution was to use WrapperQueryBuilder. However, it throws exception "no [query] registered for [query]".

Appreciate any help on this. Thanks very much.


(system) #2

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