分布式搜索引擎Elasticsearch

Elasticsearch是一个基于Lucene库的开源分布式搜索引擎,它被设计用于云计算中,能够实现快速、near-real-time的搜索,并且可以进行大规模的分布式索引。

以下是一个简单的Python代码示例,展示如何使用Elasticsearch的Python客户端进行基本的索引、搜索操作:

from elasticsearch import Elasticsearch

连接到Elasticsearch

es = Elasticsearch("http://localhost:9200")

创建一个索引

es.indices.create(index='my_index', ignore=400)

添加一个文档到索引

doc = {

'name': 'John Doe',

'age': 30,

'about': 'I love to go rock climbing'

}

res = es.index(index='my_index', id=1, document=doc)

搜索索引

res = es.search(index='my_index', query={'match': {'name': 'John'}})

打印搜索结果

print(res'hits''hits')

这段代码首先导入了Elasticsearch模块,然后创建了一个连接到本地Elasticsearch实例的客户端。接着,它创建了一个名为my_index的新索引,添加了一个文档,并进行了一个基本的搜索,搜索名字中包含"John"的记录。最后,它打印出搜索结果。这个示例提供了使用Elasticsearch进行基本操作的框架,并且可以作为开始学习的起点。

相关推荐
阿里云大数据AI技术2 小时前
Agentic Search 2.0:从单轮对话迈向企业级 AI 搜索自动驾驶Agent
人工智能·elasticsearch·agent
这个DBA有点耶3 小时前
2026年分布式数据库有哪些主流选择?先评估这5个维度再决定
数据库·分布式·dba
Elasticsearch5 小时前
你的 AI agent 需要一个不在场证明:Elastic 中 Agent Builder 的可观测性和审计追踪
elasticsearch
Elasticsearch9 小时前
仪表板活动日志:了解哪些 Kibana 仪表板会被使用
elasticsearch
Elasticsearch1 天前
从 22.61GB 到 15.63GB:Elasticsearch 9.5 如何用「混合存储」重新定义日志数据库
elasticsearch
Elasticsearch1 天前
用于自托管 LLM 调优的 vLLM Prometheus 指标:TTFT、KV Cache 和 GPU 利用率
elasticsearch
Lost of 程序猿1 天前
ASP.NET Core Saga 分布式事务深度实战:备件采购跨服务长流程,如何保证“要么全成,要么全回“
分布式·后端·asp.net
XiYang-DING1 天前
地图城市缓存优化:ApplicationReadyEvent + Caffeine + Redis + Redisson 分布式锁
redis·分布式·缓存
SEO_juper1 天前
实体SEO:从关键词到实体的2026搜索引擎与AI引用实战指南
人工智能·搜索引擎·seo·独立站·谷歌优化
2601_962175661 天前
RabbitMQ 的工作模式
分布式·rabbitmq