Elasticsearch-dsl-py: Search().query() have a error

Created on 29 Aug 2017  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

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 "", line 1
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"}}}})

Most helpful comment

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")

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zahir-koradia picture zahir-koradia  路  3Comments

vanzi picture vanzi  路  4Comments

rokcarl picture rokcarl  路  4Comments

leoliuxd picture leoliuxd  路  4Comments

berinhard picture berinhard  路  3Comments