news 2026/6/13 6:40:33

Elasticsearch(2) i have studied some basic knowledge of es , would you tell me more ?

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Elasticsearch(2) i have studied some basic knowledge of es , would you tell me more ?

Awesome! Since you’ve already wrestled with indices, documents, CRUD operations, and the nuances of mappings, you’ve made it past the hardest part of the beginner learning curve.

Now it’s time to look under the hood and see why Elasticsearch is actually used in the real world:speed, scale, and powerful search.

Here are the three big concepts you should learn next to move from a beginner to an intermediate user.


1. How ES Actually Searches: Inverted Indices

Traditional databases use B-Trees to look up data row by row. Elasticsearch does something completely different: it uses anInverted Index.

Imagine the index at the back of a textbook. Instead of reading the whole book to find where “chocolate” is mentioned, you look up the word “chocolate” in the index, and it tells you exactly which page numbers (or Document IDs) contain it.

When you index a document, Elasticsearch breaks your text into individual lowercase words (calledtokens) and builds this map:

Token (Word)Document IDs
chocolateDoc 1, Doc 3
cookiesDoc 1, Doc 2
perfectDoc 1

Because of this structure, when you search for “chocolate cookies,” Elasticsearch doesn’t scan your entire database. It instantly looks at the table, findsDoc 1, and returns it. This is why ES can search terabytes of data in milliseconds.


2. Distributed Architecture: Shards and Replicas

Elasticsearch isn’t just a database; it’s a cluster of machines (nodes) working together. To handle massive amounts of data, ES breaks an index down into smaller pieces calledShards.

There are two types of shards you need to know:

  • Primary Shards:This is where your data is split up and written. If you have 3 primary shards, your data is divided across them.
  • Replica Shards:These are exact copies of your primary shards.

Why does this matter?

  1. High Availability:If the computer holding your Primary Shard crashes, Elasticsearch instantly promotes the Replica Shard to take its place. You lose zero data.
  2. Search Performance:When you run a search, Elasticsearch asksallshards to search their piece of the data at the exact same time. It’s a “divide and conquer” strategy.

3. Advanced Searching: Queries vs. Filters

When you start writing complex searches using the_searchendpoint, you will quickly notice there are two ways to look for data:Query contextandFilter context. Knowing when to use which is the secret to making ES incredibly fast.

Query Context (The “How well does it match?” score)

Use queries when you are searching text fields where spelling might not be exact, or you care about relevance. Elasticsearch calculates aRelevance Score (_score)to rank results.

  • Example:Searching for “best chocolate cookie recipe”.
  • ES Behavior:Looks for matches, ranks them, and doesnotcache the results because every search is slightly different.

Filter Context (The “Yes or No” check)

Use filters for exact matches, numbers, dates, or status flags where there is no “ranking”—it either matches or it doesn’t.

  • Example:Is thebaking_time_minutesless than 15? Is the statusactive?
  • ES Behavior:It answers Yes/No, gives a score of0, andcaches the results in memory.
GET/recipes/_search{"query":{"bool":{"must":[{"match":{"title":"chocolate"}}<--Query(Scored)],"filter":[{"range":{"baking_time_minutes":{"lte":15}}}<--Filter(Cached,Fast!)]}}}

4. Aggregations (The Analytics Engine)

The final superpower to learn isAggregations(or “Aggs”). This is Elasticsearch’s equivalent to SQL’sGROUP BY, but on steroids. It allows you to build complex analytical dashboards instantly.

There are two main types:

  • Bucket Aggregations:Group your documents into buckets (e.g., group recipes by “ingredient”).
  • Metric Aggregations:Calculate math on those buckets (e.g., find theaveragebaking time for each ingredient group).
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/13 5:51:13

ChatGPT 10亿用户,OpenAI 说:聊天已死

OpenAI 内部有个人说了一句话。 「Chat is dead.」 聊天已死。 这话不是键盘侠在推特上喊的&#xff0c;是 OpenAI 一位高管&#xff0c;在公司内部讲的。说完这句话之后&#xff0c;OpenAI 做了一件事&#xff0c;把 ChatGPT 这个全球用户最多的 AI 产品&#xff0c;从一个聊天…

作者头像 李华
网站建设 2026/6/13 7:39:14

SpringBoot 如何实现单点登录(荣耀典藏版)

大家好&#xff0c;我是月夜枫。 在微服务、多子系统、多后台项目开发中&#xff0c;经常会遇到多个系统需要统一登录的需求&#xff1a;用户只需要登录一次&#xff0c;所有关联子系统全部认证通过&#xff0c;无需重复输入账号密码&#xff0c;这种方案就是单点登录 SSO&…

作者头像 李华
网站建设 2026/6/13 7:02:21

gotifyserver:自己搭一个消息推送服务

文章目录gotify/server&#xff1a;自己搭一个消息推送服务它能做什么生态比较完整适合什么场景实际用起来的感受总结gotify/server&#xff1a;自己搭一个消息推送服务 很多开发者都需要消息推送功能&#xff0c;但市面上的方案要么依赖第三方平台&#xff0c;要么收费不低。…

作者头像 李华
网站建设 2026/6/13 13:31:24

ReAct Agent_使用coze实现autogpt_使用Trae模拟react agent工作过程_思维链思想---AI大模型系统从零开始0007

就是这样一轮一轮的,拼接提示词,最终解决了问题。 当然上面都是我们手动的拼接提示词的,但是实际上,应该由代码去自动拼接就可以了。 然后上面的整个过程,有个coze的智能体这里做了一个也是可以复现这个过程。 点击就可以去看了。 对应的文件也都有了 然后

作者头像 李华
网站建设 2026/6/13 11:11:21

从零吃透 Git 仓库:本地+远程完整实操指南(新手保姆级)

很多初学编程、做项目的朋友&#xff0c;最头疼的不是写代码&#xff0c;而是代码管理&#xff1a;文件改来改去分不清版本、误删代码无法恢复、换电脑项目全部重来、多人协作代码混乱冲突。而 Git 仓库 就是解决所有问题的核心工具。本文不讲晦涩原理&#xff0c;只讲能直接落…

作者头像 李华