Utkarsh Gupta Utkarsh Gupta - 5 months ago 39
JSON Question

Querying ElasticSearch using a JSON file through JAVA API

I have a query in valid JSON format which works well in kibana or Sense when I use GET request.I am also able to create this query using XContentBuilder, but I need to send this query using its JSON form as it is to ElasticSearch. Is it possible to store the query in a JSON file and query ElasticSearch using this JSON file.

My query -

"sort" : [
"_geo_distance" : {
"location" : [40.715, -73.988],
"order" : "asc",
"unit" : "km",
"mode" : "min",
"distance_type" : "arc"
"query": {
"bool": {
"must": {
"query_string": {
"query": "hospital",
"analyzer": "english"
"filter": {
"geo_distance": {
"distance": "50000km",
"location": {
"lat": 40.715,
"lon": -73.988

What I want is to store this query in a JSON file and use this JSON file to send a search request directly without using Query builder.

alr alr
Answer Source

You can use a search template, and store this template in the cluster state, see the official documentation about search templates, especially about pre-registered templates.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download