【发布时间】:2018-07-03 00:34:29
【问题描述】:
我试图理解为什么带有单个下划线 mods_genre 的字段的行为与带有 1+ 下划线的字段的行为不同,例如mods__genre 使用python时elasticsearch-dsl client。
使用 ElasticSearch 版本 5.5.1 和 python 3.5。
以下是我正在使用的代码,用于选择字段与值匹配的所有文档。
此示例正在搜索索引foo,其字段名称只有一个下划线,并按预期返回结果(我已确认此字段填充了此值):
# query against index with single underscores in field name
query = Search(using=es_handle, index='foo')
query = query.filter(Q('term', **{'%s.keyword' % 'mods_genre' : 'biography'}))
query_results = query.execute()
In [16]: query_results.hits.total
Out[16]: 6
但是,使用非常相似的代码,但查询具有连续多个下划线的字段名称的索引bar,我得到的结果为零:
# query against index with multiple underscores in field name
query = Search(using=es_handle, index='bar')
query = query.filter(Q('term', **{'%s.keyword' % 'mods__genre' : 'biography'}))
query_results = query.execute()
In [16]: query_results.hits.total
Out[16]: 0
对为什么会出现这种情况有任何见解吗?我知道以下划线开头的字段名称是保留的,但没有偶然发现任何指示字段内下划线的文档 - 特别是连续多个下划线 - 会有问题。
【问题讨论】:
标签: elasticsearch elasticsearch-dsl-py