I'm trying to query elasticsearch
using python requests
. Following this post, I'm using the following process:
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)
Unfortunately, the quotation marks in the query don't appear to be properly escaped for elasticsearch. I've also tried:
'\\"text in quotes\\"'
response = requests.get(url, data=json.dumps(params))
The equivalent curl, which works, looks as follows:
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,
}'