0

我的 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,因为它应该是一样的。

什么是正确的方法?

4

1 回答 1

1

不,使用它的正确方法是 withname.raw因为那是not_analyzed. 如果你只使用name你不使用的not_analyzed版本,你使用standard分析器的分析版本。

这就是为什么filter('term', name='foo'})匹配foofoo-1

于 2016-07-14T10:31:00.183 回答