Querying Elasticsearch with escaped quotes in python requests
<p>I'm trying to query <code>elasticsearch</code> using python <code>requests</code>. Following <a href="https://stackoverflow.com/questions/15930235/querying-elasticsearch-with-python-requests-not-working-fine">this post</a>, I'm using the following process:</p>

<pre><code>params = {
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "query_string": {
                                "query": r'\"text in quotes\"'
                            }
                        }
                    ]
                }
            },
            "filter": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "@timestamp": {
                                    "from": 1458581389860,
                                    "to": 1458494989000
                                }
                            }
                        }
                    ]
                }
            }
        }
    },
    "size": 100,
}
response = requests.get(url, params=params)
</code></pre>

<p>Unfortunately, the quotation marks in the query don't appear to be properly escaped for elasticsearch. I've also tried:</p>

<ul>
<li><code>'\\"text in quotes\\"'</code></li>
<li><code>response = requests.get(url, data=json.dumps(params))</code></li>
</ul>

<p>The equivalent curl, which works, looks as follows:</p>

<pre><code>curl -XGET 'MYURL/_search?pretty' -d '{
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "query_string": {
                                "query": "\"test in quotes\""
                            }
                        }
                    ]
                }
            },
            "filter": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "@timestamp": {
                                    "from": 1458581389860,
                                    "to": 1458494989000
                                }
                            }
                        }
                    ]
                }
            }
        }
    },
    "size": 100,
}'
</code></pre>