elasticsearch各个分词效果测试
from elasticsearch import Elasticsearch
es = Elasticsearch()
text = "10万左右口碑最好的车 "
# 使用 Elasticsearch 的 standard 分词器分析文本
tokens = es.indices.analyze(index="new_cars",body={'text': text, 'analyzer': 'standard'})
print("使用 standard 分词器分析文本:")
for token in tokens['tokens']:
print(token['token'])
# 使用 Elasticsearch 的 ik_max_word 分词器分析文本
tokens = es.indices.analyze(index="new_cars",body={'text': text, 'analyzer': 'ik_max_word'})
print("\n使用 ik_max_word 分词器分析文本:")
for token in tokens['tokens']:
print(token['token'])
# 使用 Elasticsearch 的 ik_smart 分词器分析文本
tokens = es.indices.analyze(index="new_cars",body={'text': text, 'analyzer': 'ik_smart'})
print("\n使用 ik_smart 分词器分析文本:")
for token in tokens['tokens']:
print(token['token'])