120.【ElastiSearch】(七)

本文涉及的产品
全局流量管理 GTM,标准版 1个月
云解析 DNS,旗舰版 1个月
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
简介: 120.【ElastiSearch】
(7).布尔值查询 - not (must_not)

即 年龄不等于23岁的...

GET /jsxs/user/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "age": "23"
          }
        }
      ]
    }
  }
}

(8).布尔值查询 range- (filter)

范围值: gte即大于等于 。lte即小于等于

GET /jsxs/user/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "name": "吉士先生2"
          }
        }
      ],
      "filter": {
        "range": {
          "age": {
            "gt": 8
          }
        }
      }
    }
  }
}

(9).多条件查询 (用空格隔开)

这里只能对同一个字段进行用空格隔开查询,也就是数组。

GET /jsxs/user/_search
{
  "query": {
    "match": {
      "tags": "男 技术2"
    }
  }
}

(10).单个值的精确查询 (keyword+term)

term 查询时直接通过倒排索引指定的词条进行精确的查找。

  1. 关于分词:
  • term,直接查询精确的。
  • match,会使用分词器解析!(先分析文档,然后再通过分析的文档进行查询)
  1. 两个类型
  • text: 不会被分词器进行解析。
  • keyword: 会被分词器解析。

1. 创建索引库

PUT testdb
{
  "mappings": {
    "properties": {
      "name":{
        "type": "text"
      },
      "desc":{
        "type": "keyword"
      }
    }
  }
}

2. 插入两条数据

PUT testdb/_doc/2
{
  "name":"狂神说Java name1",
  "desc":"狂神说Java desc1"
}

3. keyword 查询不会被分词器解析

GET _analyze
{
  "analyzer": "keyword",
  "text": "狂神说Java name1"
}

4. text会被分词器给解析,standard默认就是text

GET _analyze
{
  "analyzer": "standard",
  "text": "狂神说Java name1"
}

  1. 精确查找

keyword+term才能精确查找,否则不会精确查找.

GET testdb/_search
{
  "query": {
    "term": {
      "desc": {
        "value": "狂神说Java desc1"
      }
    }
  }
}

(11).多个值匹配精确查询

多个值的精确查询

GET testdb/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "t1": {
              "value": "22"
            }
          }
        },
        {
          "term": {
            "t1": {
              "value": "33"
            }
          }
        }
      ]
    }
  }
}

(12).高亮查询
  1. 高亮查询
"highlight": {
    "fields": {
      "name":{}  给name字段进行操作
    }
  }
GET jsxs/user/_search
{
  "query": {
    "match": {
      "name": "吉士先生"
    }
  },
  "highlight": {
    "fields": {
      "name":{}
    }
  }
}

  1. 更改高亮样式 (自定义高亮样式)
"highlight": {
    "fields": {
      "name":{}
    }
  }
GET jsxs/user/_search
{
  "query": {
    "match": {
      "name": "吉士先生"
    }
  },
  "highlight": {
    "pre_tags": "<p class='key' style='color:red'>", 
    "post_tags": "</p>", 
    "fields": {
      "name":{}
    }
  }
}

相关文章
|
索引
120.【ElastiSearch】(十)
120.【ElastiSearch】
59 1
|
SQL JavaScript 数据可视化
120.【ElastiSearch】(二)
120.【ElastiSearch】
56 0
|
搜索推荐 Java 大数据
120.【ElastiSearch】(一)
120.【ElastiSearch】
67 0
|
存储 监控 关系型数据库
120.【ElastiSearch】(三)
120.【ElastiSearch】
97 0
|
自然语言处理 算法 数据库
120.【ElastiSearch】(四)
120.【ElastiSearch】
55 0
|
JSON Java 数据格式
120.【ElastiSearch】(六)
120.【ElastiSearch】
59 0
|
5月前
|
存储 自然语言处理 搜索推荐
【技术解析 | 实践】Havenask分析器
本次分享内容为Havenask的分析器,本次课程主要分为3部分内容(分析器介绍、解释分析器主要配置、实战演示),希望本次通过分享帮助大家更好了解和使用Havenask。
52248 3
【技术解析 | 实践】Havenask分析器
|
4月前
|
网络安全 数据库 Python
常用百宝箱——日志处理
常用百宝箱——日志处理
|
缓存 网络架构 索引
120.【ElastiSearch】(五)
120.【ElastiSearch】
38 0
|
NoSQL Java
120.【ElastiSearch】(八)
120.【ElastiSearch】
57 0