elasticsearch (dsl)

正排索引 和 倒排索引

正排索引:通过id ,查询content

倒排索引:通过content,查询到符合的 ids

eg:

通过《静夜思》,找到整片文章。

通过"明月",找到《静夜思》 《望月怀古》《关山月》等

get 查询

索引的基本信息:

GET your_index/_mapping //跟看mysql表字段差不多

GET your_index/_alias //查看索引的别名

GET /_cat/health?v //查看集群状态

GET _cat/indices // 查看所有index

GET _cat/shards/your_index //查看指定索引的分片数,每个分片有主(p)副(r)分片

查询索引内容:

match_all:

复制代码
GET /you_index/_search
{
  "query":{
    "match_all": {}
}

bool

bool查询是一个非常强大且常用的复合查询,它允许你组合多个查询条件。bool 查询的核心概念包括以下四种子句:

  1. must : 子句必须匹配文档。类似于 SQL 中的 AND 操作符。
  2. filter : 子句必须匹配文档,但不影响评分。也就是说,它只过滤文档,但不参与评分计算。
  3. should : 子句可以匹配文档。如果在一个 bool 查询中包含了多个 should 子句,则至少一个 should 子句必须匹配文档。类似于 SQL 中的 OR 操作符。
  4. must_not: 子句不能匹配文档。类似于 SQL 中的 NOT 操作符。

eg:

复制代码
GET you_index/_search
{
  "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "term": {
                                    "name": {
                                        "value": "林俊凯",
                                        "boost": 1
                                    }
                                }
                            },
                            {
                                "term": {
                                    "zh_name": {
                                        "value": "林俊凯",
                                        "boost": 1
                                    }
                                }
                            }
                        ]
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "range": {
                                    "fans_num": {
                                        "gte": "800"
                                    }
                                }
                            },
                            {
                                "terms": {
                                    "tag": [
                                        1010,
                                        1013
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "sort": {
        "_score": {
            "order": "desc"
        },
        "score": {
            "order": "desc"
        }
    }
}

range

复制代码
    "range": {
            "fans_num": {
              "gte": 800,
              "lte":126334
            }
     }

term

terms

prefix

multi_match

multi_phrase

analyzer

mla

standard

keyword

slop

3<80%

相关推荐
samLi06202 小时前
【工具变量】全国省市区县土地出让结果公告数据(2000-2024年)
大数据
chevysky.cn4 小时前
Elasticsearch部署和集成
大数据·elasticsearch·jenkins
SelectDB技术团队5 小时前
森马服饰从 Elasticsearch 到阿里云 SelectDB 的架构演进之路
elasticsearch·阿里云·doris
青云交6 小时前
Java 大视界 -- Java 大数据在智能医疗远程手术机器人操作数据记录与分析中的应用(342)
java·大数据·数据记录·远程手术机器人·基层医疗·跨院协作·弱网络适配
Elasticsearch6 小时前
Elastic 被评为 2025 年 Gartner® 可观测平台魔力象限™中的领导者
elasticsearch
武子康6 小时前
大数据-38 Redis 分布式缓存 详细介绍 缓存、读写、旁路、穿透模式
大数据·redis·后端
Elasticsearch6 小时前
上下文更长 ≠ 更好:为什么 RAG 仍然重要
elasticsearch
时序数据说6 小时前
时序数据库的存储之道:从数据特性看技术要点
大数据·数据库·物联网·开源·时序数据库·iotdb