4

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 -

{
  "min_score":5,
  "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.

2
  • This is not well supported by the offical ES API: discuss.elastic.co/t/… Commented Aug 26, 2017 at 12:46
  • 1
    Yeah, it was possible in the earlier versions, but the current version of ES does not support it. Commented Aug 26, 2017 at 15:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, Search templates can be used to send this json query directly to elastic search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.