elasticsearch使用笔记(一)

elasticsearch使用笔记(一)

刚刚接触elasticsearch,真的是超好用了,本笔记主要记录使用Python调用es的基本操作

elasticsearch重启

重启一般都可以解决connection error之类的问题

  1. cd到elasricsearch文件路径下的bin文件中
  2. su es
  3. nohup ./elasticsearch >/dev/null 2>&1 &
  4. ps -ef|grep elasticsearch
  5. 搞定

加载

from elasticsearch import Elasticsearch, helpers
es = Elasticsearch(['http://localhost'], port=9200, timeout=60)

Python API 得到并修改mapping,setting

es.indices.get_mapping(index=index)
es.indices.get_settings(index=index)
es.indices.put_mapping(index=index, doc_type=type, body=new_mapping)

Python API 创建、删除索引

es.indices.create(index=index)
es.indices.delete(index=index)

Python API 批量导入数据

data = [{"_index": index,"_type": type,  "_source":x } for x in raw_data]
helpers.bulk(self.es, data)

Python API 复制一个索引的数据至一个新的索引

helpers.reindex(client=client, source_index=source_index, target_index=target_index, target_client=client,
                        query= {"query": {"match_all": {}  }, chunk_size=1000, scroll='15m')

Python API 搜索

 results = es.search(index=index, body=query)

搜索并打印每段query的得分(explain)

es.search(index=index, body=query, explain=True)

但是速度会变慢

更换相似度模型

以为默认的是TFIDF,后来mapping设置为bm25之后发现没有差别。才晓得目前版本默认bm25相似度打分,之后用到再补充

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值