【发布时间】:2016-07-14 08:42:13
【问题描述】:
我的 elasticsearch_dsl 类中有一些东西我想查询精确匹配:
class Profile(DocType):
name = String(fields={'raw': String(index='not_analyzed')})
虽然这确实有效,但我总是需要在查询中添加 .raw 并且无法准确查询 name:
# Matches "foo" and "foo-1"
Profile.search().filter('term', name='foo'})
# Matches nothing
Profile.search().filter('term', name='foo-1'})
# Matches what i want (only "foo-1")
Profile.search().filter('term', **{'name.raw': 'foo-1'})
这感觉有点不对,因为我应该可以只使用name 而不是raw,因为它应该是一样的。
什么是正确的方法?
【问题讨论】:
-
您只需要将您的主字段索引为
not_analyzed,但首选的方法是使用您现在拥有的raw字段。 -
我确实将它索引为
not_analyzed,请参阅我附加的 DocType 类。
标签: elasticsearch elasticsearch-dsl elasticsearch-py