python elasticsearch-dsl elasticsearch 字段名称中的多个下划线
multiple underscores in elasticsearch field name with python elasticsearch-dsl
我试图理解为什么具有单个下划线的字段 mods_genre
与具有 1 个以上下划线的字段的行为不同,例如mods__genre
当使用 python elasticsearch-dsl client.
使用 ElasticSearch 版本 5.5.1
和 python 3.5
.
以下是我正在使用的代码,用于 select 字段与值匹配的所有文档。
此示例正在搜索一个索引 foo
,其字段名称只有一个下划线,并且 returns 结果符合预期(因为我已确认此字段已填充此值) :
# 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
是否了解为什么会出现这种情况?我知道以下划线开头的字段名称是保留的,但没有偶然发现任何指示字段内下划线的文档——特别是连续多个下划线——会有问题。
我试图理解为什么具有单个下划线的字段 mods_genre
与具有 1 个以上下划线的字段的行为不同,例如mods__genre
当使用 python elasticsearch-dsl client.
使用 ElasticSearch 版本 5.5.1
和 python 3.5
.
以下是我正在使用的代码,用于 select 字段与值匹配的所有文档。
此示例正在搜索一个索引 foo
,其字段名称只有一个下划线,并且 returns 结果符合预期(因为我已确认此字段已填充此值) :
# 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
是否了解为什么会出现这种情况?我知道以下划线开头的字段名称是保留的,但没有偶然发现任何指示字段内下划线的文档——特别是连续多个下划线——会有问题。