10

Anyone know of a way to send a JSON query to an ElasticSearch server via HTTP GET? I know you can POST the JSON content to _search, but POST is not available because this is cross-domain. For example, if my query looks like this:

{
    "query": {
        "query_string": {
            "fields": ["name", "description"],
            "query": "Elastic Search"
        }
    }
}

Which I would convert to something like:

{"query":{"query_string":{"fields":["name","description"],"query":"Elastic Search"}}}

Is there a way to GET server:9200/index/type/_search?content=stringifiedquery or something similar? I've tried q= and content= as well as just passing the content after the ? but nothing seems to work. Anyone have any ideas? Or am I just out of luck?

inxilpro
  • 20,094
  • 2
  • 24
  • 28

1 Answers1

12

You can use the source query string parameter to send what would normally be the post body.

See the bottom of this page: http://www.elasticsearch.org/guide/reference/api/

DrTech
  • 17,031
  • 5
  • 54
  • 48
  • Will using source as the key value also work for POST requests? I ask because I'm trying to use RestKit (ObjC framework for json req/resp) and it tends to require key-value pairs for the json data (value) that is attached to the post request parameters being sent to the ElasticSearch instance. – pulkitsinghal Jan 23 '12 at 02:54
  • This is awesome. I notice that this parameter is not documented here: https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-uri-request.html Does anyone know if this is a deprecated feature that will eventually stop working in future releases? It appears to be working as expected in ES 1.5.2. – Tony Cesaro Jun 22 '15 at 19:32
  • 1
    @TonyCesaro it's small but it's there: https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#_request_body_in_query_string – DrTech Jun 23 '15 at 17:11