python中的Elasticsearch操作匯總
更新時間:2019年10月30日 16:52:30 作者:simpleknight
這篇文章主要介紹了python中的Elasticsearch操作匯總,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
這篇文章主要介紹了python中的Elasticsearch操作匯總,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
導(dǎo)入包
from elasticsearch import Elasticsearch
本地連接
es = Elasticsearch(['127.0.0.1:9200'])
創(chuàng)建索引
es.indices.create(index="python_es01",ignore=400)
ingore=400 ingore是忽略的意思,400是未找到
刪除索引
es.indices.delete(index="python_es01")
檢查索引是否存在
es.indices.exists(index="python_es01")
插入數(shù)據(jù)
es.index(index="python_es01",doc_type="doc",id=1,body={"name":"kitty","age":50})
同時也可以不加id,即
es.index(index="python_es01",doc_type="doc",body={"name":"kitty","age":10})
查詢操作
按id查詢
result = es.get(index="python_es01",doc_type="doc",id=1)
會有一個返回值
全查
body= { "query":{ "match_all":{} } } result = es.search(index="python_es01",body=body)
使用id的用GET,其他search
刪除操作
result = es.delete(index="goods",doc_type="type1",id=2)
按查詢結(jié)果刪除
result = es.delete_by_query(index="goods",body=body)
建立mapping
body = { "mappings": { "properties": { "name": { "type": "text" }, "price": { "type": "long" } } } } result = es.indices.create(index="shang",body=body)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python中ndarray數(shù)組的索引和切片的使用
本文主要介紹了python中ndarray數(shù)組的索引和切片的使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07