elasticsearch基础命令

1 字段分词分析:

复制代码
GET /store_info_data/_analyze
{
  "field": "storeName",
  "text":"20pilapala0"
}

2 精确查找,去除评分

复制代码
GET /store_info_data/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "term": {
          "price": "30"
        }
      }
    }
  }
}

3 组合查询案例

SELECT product FROM products

WHERE (price = 20 OR productID = "XHDK-A-1293-#fJ3")

AND (price != 30)

复制代码
GET /store_info_data/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "term": {
            "price": 30
          }
        }
      ],
      "should": [
        {
          "term": {
            "price": 20
          }
        },
        {
          "match": {
            "productID": "XHDK-A-1293-#fJ3"
          }
        }
      ]
    }
  }
}

SELECT document FROM products

WHERE productID = "KDKE-B-9947-#kL5"

OR ( productID = "JODL-X-1937-#pV7" AND price = 30 )

复制代码
GET /store_info_data/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "productID":  "KDKE-B-9947-#kL5"
            
          }
        },
        {
          "bool": {
            "must": [
              {
                "match": {
                  "productID":  "JODL-X-1937-#pV7"
                  
                }
                
              },
              {
                "term": {
                  "price": {
                    "value": "30"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

4 范围查找

gt: > 大于(greater than)
lt: < 小于(less than)
gte: >= 大于或等于(greater than or equal to)
lte: <= 小于或等于(less than or equal to)

  • 如果我们想查找时间戳在过去一小时内的所有文档:

    "range" : {
    "timestamp" : {
    "gt" : "now-1h"
    }
    }

  • 日期计算还可以被应用到某个具体的时间,并非只能是一个像 now 这样的占位符。只要在某个日期后加上一个双管符号 (||) 并紧跟一个日期数学表达式就能做到:

    • 早于 2014 年 1 月 1 日加 1 月(2014 年 2 月 1 日 零时)

      "range" : {
      "timestamp" : {
      "gt" : "2014-01-01 00:00:00",
      "lt" : "2014-01-01 00:00:00||+1M"
      }
      }

4 exists(存在) & must_not + exists(不存在)

  • exists 用法 判断数据不为null

    GET store_info_data/_search
    {
    "query": {
    "constant_score": {
    "filter": {
    "exists": {
    "field": "author"
    }
    },
    "boost": 1.2
    }
    }
    }

  • must_not + exists用法

    GET store_info_data/_search
    {
    "query": {
    "bool": {
    "must_not": {
    "exists": {
    "field": "name"
    }
    }
    }
    }
    }

5 新增数据

复制代码
# POST
POST my-index-000001/_doc
{
  "my_float":   "2.0", 
  "my_integer": "3" 
}

# PUT 
PUT my-index-000001/_doc/2
{
  "my_float":   "2.0", 
  "my_integer": "3" 
}
相关推荐
MAGICIAN...5 小时前
【Redis】--持久化机制
数据库·redis·缓存
我真的是大笨蛋6 小时前
JVM调优总结
java·jvm·数据库·redis·缓存·性能优化·系统架构
步步为营DotNet7 小时前
5-2EFCore性能优化
数据库·性能优化·.net
2501_920047038 小时前
Redis-集群
数据库·redis·bootstrap
半夏陌离8 小时前
SQL 拓展指南:不同数据库差异对比(MySQL/Oracle/SQL Server 基础区别)
大数据·数据库·sql·mysql·oracle·数据库架构
旋转的油纸伞9 小时前
SQL表一共有几种写入方式
数据库·sql
半夏陌离9 小时前
SQL 入门指南:排序与分页查询(ORDER BY 多字段排序、LIMIT 分页实战)
java·前端·数据库
isyoungboy9 小时前
SQL高效处理海量GPS轨迹数据:人员gps轨迹数据抽稀实战指南
数据库·sql
敬业小码哥9 小时前
记一次:mysql的json及json数组使用组合使用
数据库·mysql·json
练小杰10 小时前
【Mysql-installer-community-8.0.26.0】Mysql 社区版(8.0.26.0) 在Window 系统的默认安装配置
数据库·sql·mysql·adb·配置文件·mysql安装·关系型数据库