Elasticsearch -- python 使用

示例:

复制代码
from elasticsearch import Elasticsearch

es = Elasticsearch(hosts="http://101.132.42.187:9200")

content = {
    "name": "sdfs",
    "age": 16,
    "xx": [11, 223, 33, 44]
}

# 创建索引并插入数据, 索引存在则更新数据
# result = es.index(index='test-01', document=content)
# print result
# print result['result']

# 获取索引test-01 下 id=1 的数据
# print es.get(index="test-01", id="1")


# 匹配 name = 小明 的数据
a = {
    "query": {
        'match': {
            "name": '小明'
        }
    }
}


print es.search(body=a)

# 匹配 索引test-01 中 name = sdfs 的数据
# a = {
#     "query": {
#         'match': {
#             'name': 'sdfs'
#         }
#     }
# }
# resp = es.search(body=a, index='test-01')
# print(resp)
# print(resp['_shards'])
复制代码

 

posted @   萤huo虫  阅读(55)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示