nino
(nino)
June 4, 2020, 6:21pm
1
Hello all,
i am trying to create this query in python but i can't find out the correct syntax. I would like to filter by date greater than and field value:
query_body = {
"size": 100,
"query": {
"match" : { "account_value":"ATT11111" }
"range": {
"@timestamp": {
"gt":str(last_trackrecord_day)
}
}
}
}
I am not expert in python but you define this body just like you have and call it
response = elastic_client.search(index="some_index", body=query_body)
where elastic_client is another file handle
elastic_client = Elasticsearch('elkm01', http_auth=('user', 'password'), port=9200)
nino
(nino)
June 4, 2020, 6:52pm
3
Thanks elasticforme, sorry, i didn't explain well. This Query works:
query_body = {
"size": 100,
"query": {
"range": {
"@timestamp": {
"gt":str(last_trackrecord_day)
}
}
}
}
This query it doesn't, sure my syntax is wrong.
query_body = {
"size": 100,
"query": {
"match" : { "account_value":"ATT11111" }
"range": {
"@timestamp": {
"gt":str(last_trackrecord_day)
}
}
}
}
```
nino
(nino)
June 4, 2020, 8:28pm
4
This try it fails too:
query_body = {
"size": 100,
"query": {
"bool": {
"must": [
{
"match" : {
"account_value": "ATT11111"
}
},
{
"range": {
"@timestamp": {
"gt":str(last_trackrecord_day)
}
}
}
]
}
}
}
Error:
elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'failed to create query
then it is just matter of figureing out what is wrong.
go to dev tool on kibana and post this there and work it out
https://discuss.elastic.co/t/combining-bool-and-range-queries/82729
nino
(nino)
June 4, 2020, 9:39pm
6
Thanks Sachin,
it seems the text value, why?:
"type": "number_format_exception",
"reason": "For input string: \"ATT11111\""
nino
(nino)
June 4, 2020, 9:52pm
7
Solved, it was my fault. The name field was incorrect with another field with numeric type. Thank you so much