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":{}
        }
      }
    }
    
    
  • 相关阅读:
    ibatis实战之一对多关联
    ibatis实战之OR映射
    ibatis配置log4j输出sql日志信息
    MyEclipse添加ibatis DTD文件实现xml的自动提示功能
    ibatis实战之基础环境搭建
    ORA-12520错误解决方法
    springMVC3学习(十二)--文件上传优化CommonsMultipartResolver
    转:sql语句优化
    转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek
    SQL Server优化
  • 原文地址:https://www.cnblogs.com/ccubee/p/14254704.html
Copyright © 2011-2022 走看看