I have a index:
"geo" : {
"properties" : {
"area" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"city" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
},
"fielddata" : true
},
"country" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"iso_code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"latitude" : {
"type" : "float"
},
"longitude" : {
"type" : "float"
}
}
}
now, code:
Search(using=client, index='m',doc_type='8').query("match",geo.iso_code="TW")
File "
Search(using=client, index='m',doc_type='8').query("match",geo.iso_code="TW")
SyntaxError: keyword can't be an expression
but, i use the code is ok:
client.search(index="m", doc_type="8", body={"size":0,"aggs":{"t_cc":{"terms":{"size":10000,"field":"geo.city.keyword"}}}})
You need to replace the geo.iso_code with geo__iso_code:
Search(using=client, index='m',doc_type='8').query("match",geo__iso_code="TW")
The problem is not in the library - Search(using=client, index='m',doc_type='8').query("match",geo.iso_code="TW") is not a valid Python code since keyword argument cannot have a dot in it. To work around it you can use double underscore in elasticsearch_dsl:
Search(using=client, index='m',doc_type='8').query("match",geo__iso_code="TW")
hope this helps!
Btw it looks like it should be Search(using=client, index='m',doc_type='8').filer("term",geo__iso_code__keyword="TW") since TW is a keyword value.
Most helpful comment
You need to replace the
geo.iso_codewithgeo__iso_code: