我有一个 Elasticsearch 数据库,其中包含多个字段,其中可以包含名称信息,并尝试像这样搜索它:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
client = Elasticsearch()
s = Search(using=client, index="names")
query = 'smith'
fields = ['name1', 'name2']
results = s.query("multi_match", query=query, fields=fields, fuzziness='AUTO')
for hit in results.scan():
print(hit.meta.score)
结果是:
None
None
None
...
但是,如果我手动构建它:
results = client.search(index="names",
body={"size": 100, "query":{
"multi_match": {
"query": query, "fields": fields, "fuzziness": 'AUTO'
}
}
})
我的结果是:
{'_index': 'names', '_type': 'Name1', '_id': '1MtYSW4BXryTHXwQ1xBS', '_score': 14.226202, '_source': {...}
{'_index': 'names', '_type': 'Name1', '_id': 'N8tZSW4BXryTHXwQHBfw', '_score': 14.226202, '_source': {...}
{'_index': 'names', '_type': 'Name1', '_id': '8MtZSW4BXryTHXwQeR-i', '_score': 14.226202, '_source': {...}
如果可能的话,我更喜欢使用 elasticsearch-dsl,但我需要分数信息。