简体   繁体   中英

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 -

{
  "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.

您可以使用搜索模板,并将此模板存储在集群状态中,请参阅有关搜索模板官方文档 ,尤其是有关预注册模板的官方文档

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM