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%

相关推荐
Bzc11456231 小时前
中医辨证调护:慢病视角下的血糖健康养护思路
大数据·人工智能·生活
Fluxart.ai1 小时前
2026电商AI出图质量验收标准与质检SOP完整教程
大数据·人工智能
泛普软件1 小时前
工程施工项目管理办公系统能解决哪些现场管理难题与超支问题
大数据·人工智能·软件需求
用户3610588626121 小时前
Spark 核心之广播变量、累加器原理深度剖析
大数据·spark
Elasticsearch1 小时前
Elasticsearch 作为统一平台:引入第二套数据系统究竟要付出什么代价
elasticsearch
A15362551 小时前
WMS 仓储系统的软件有哪些?2026 主流产品分类与选型参考
大数据·人工智能
hopsky2 小时前
《HBase 权威指南》 Lars George
大数据·数据库·hbase
Elastic 中国社区官方博客2 小时前
Elasticsearch:列式索引模式 - Columnar index mode
大数据·数据库·elasticsearch·搜索引擎·全文检索
Elasticsearch2 小时前
Elasticsearch 的批量查询阶段如何在大规模场景下提升搜索性能
elasticsearch
仍然.2 小时前
服务端高并发分布式结构演进之路
大数据·数据库·redis