python elasticsearch实现精准查询与bm25查询
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import Match
1)连接 Elasticsearch
es = Elasticsearch(['http://127.21.0.0:9200'],
http_auth=('elastic', '123456')) # 替换为你的用户名和密码
2)创建es索引
your_index_name= 'my_es_index' # 设置自己的es索引名称
es.indices.create(index=your_index_name, ignore=400)
定义文档映射
映射(Mapping) 是指定义文档及其包含的字段如何存储和索引的过程。
doc_mapping = {
"properties": {
"content": {