zoukankan      html  css  js  c++  java
  • ESrest基本操作

    前排提示

    本文整理自b站狂神说 Es课程

    测试ik分词器是否生效

    GET _analyze
    {
      "analyzer": "ik_smart",
      "text":"今天天气不错"
    }
    

    put创建索引

    PUT /test1/type1/1 
    {
      "name":"测试1",
      "age":"18"
    }
    
    PUT /test1/_doc/1 
    {
      "name":"测试1",
      "age":"18"
    }
    

    指定字段类型

    PUT /test2
    {
      "mappings": {
        "properties": {
          "name": {
          "type":"text"
        },
        "age":{
          "type":"long"
        },
        "birthday":{
          "type" :"date"
        }
        }
        
      }
    }
    

    修改索引

    put覆盖索引

    POST /test3/_doc/2/_update
    {
      "doc":{
        "name":"修改测试3"
      }
    }
    

    删除索引

    DELETE test3
    

    查询索引

    GET test3/_doc/2
    
    GET test3/_doc/_search?q=name:测试
    

    复杂查询

    score 匹配度
    _soutce 指定输出字段

    GET test3/_doc/_search
    {
      "query": {
        "match": {
          "name":"测试"
        }
      },
      "_source":["name"]
    }
    
    

    排序

    GET test3/_doc/_search
    {
      "query": {
        "match": {
          "name":"测试"
        }
      },
      "sort": [
        {
         "age": {
           "order":"desc"
         }
        }
        ]
    }
    

    分页查询

    from 第几个开始
    size 每页条数

    GET test3/_doc/_search
    {
      "query": {
        "match": {
          "name":"测试"
        }
      },
      "sort": [
        {
         "age": {
           "order":"desc"
         }
        }
        ],
        "from":0,
        "size" :2
    }
    
    

    布尔值查询 多条件查询

    must = and 所有条件都要匹配
    should = or 匹配一个就可以查询出来

    must_not = not 不是的

    
    GET test3/_doc/_search
    {
      "query": {
        "bool": {
          "must" :[
            {
              "match": {
                "name":"测试"
              }
            },
            {
              "match" :{
                "age":18
              }
            }
            ]
        }
      }
    
    }
    

    过滤器

    filter

    GET test3/_doc/_search
    {
      "query": {
        "bool": {
          "must" :[
    
            {
              "match" :{
                "name":"测试"
              }
            }
            ],
            "filter" : {
              "range": {
                "age" :{
                  "gte":"20",
                  "lte":"30"
                }
              }
            }
        }
      }
    
    }-
    
    

    精确查询

    • term 精确查找
    • match
      keyword 无法分割

    高亮查询

    • highlight 设置高亮字段
    GET test3/_search
    {
      "query": {
              "match": {
                 "name": "测试"
              }
    
      },
      "highlight" :{
        "fields" :{
          "name":{}
        }
      }
    }
    
    
  • 相关阅读:
    PHP 求多个数组的笛卡尔积,适用于求商品规格组合 【递归思想, 类似广度优先搜索】【原创】
    CCF推荐期刊会议
    SCI分区
    值和指针接收者的区别
    程序员练级攻略
    保险
    golang 有缓冲channel和无缓冲channel
    后台学习路线
    golang之反射
    atomic和mutex
  • 原文地址:https://www.cnblogs.com/ccubee/p/14254704.html
Copyright © 2011-2022 走看看