How to convert CURL into URI in Elasticsearch

2019-08-09 12:23发布

问题:

I have a curl command for elasticsearch aggregation as below.

curl -XGET "http://localhost:9200/employee/_search?search_type=count&pretty" -d '{
  "aggregations": {
    "profile": {
      "terms": {
        "field": "_type"
      },
      "aggs": {
        "hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}'

I want to search these above curl into my htmlpage in browser, how to convert this into normal url like URI search in elasticsearch ?

Please help me to convert above to url ?

回答1:

You can use the source query string parameter in order to pass the body directly in the URL

curl -XGET 'http://localhost:9200/employee/_search?search_type=count&pretty&source={"aggregations":{"profile":{"terms":{"field":"_type"},"aggs":{"hits":{"top_hits":{"size":1}}}}}}'
                                                                              ^
                                                                              |
                                                           use the source parameter