• es常用查询学习记录


    DELETE /test

    PUT /test
    {
    "settings": {
    "number_of_shards": 10,
    "number_of_replicas": 1
    }
    }

    DELETE /employee
    ##非结构化新建索引

    PUT /employee
    {
    "settings": {
    "number_of_replicas": 1
    , "number_of_shards": 1
    }
    }


    PUT /employee/_doc/1
    {
    "name":"凯杰2",
    "age":30
    }


    PUT /employee/_doc/1
    {
    "name":"凯杰3"
    }

    ##获取索引记录
    GET /employee/_doc/1

    #指定字段修改
    POST /employee/_update/1
    {
    "doc": {
    "name":"凯杰4"
    }
    }

    #强制指定创建,若已经存在则失败
    POST /employee/_create/6
    {
    "name":"兄长2",
    "age":"31"
    }

    #删除某个文档
    DELETE /employee/_doc/2

    #查询全部文档
    GET /employee/_search

    #使用结构化的方式创建索引
    PUT /employee
    {
    "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
    },
    "mappings": {
    "properties": {
    "name":{"type":"text"},
    "age":{"type": "integer"}
    }
    }
    }

    #不带条件查询所有记录的方法
    GET /employee/_search
    {
    "query": {
    "match_all": {}
    }
    }

    #分页查询
    GET /employee/_search
    {
    "query": {
    "match_all": {}
    }
    , "from": 0,
    "size": 2
    }

    #带关键字条件查询
    GET /employee/_search
    {
    "query":{
    "match": {
    "name": "兄"
    }
    }
    }

    #带排序
    GET /employee/_search
    {
    "query":{
    "match": {
    "name": "兄"
    }
    }, "sort":[
    {"age":{"order":"asc"}}
    ]
    }

    #带filter term完全匹配 match 分词匹配
    GET /employee/_search
    {
    "query": {
    "bool": {
    "filter": [
    {"term":{"name":"兄111"}}
    ]
    }
    }
    }

    #带聚合
    GET /employee/_search
    {
    "query": {
    "match": {
    "name": "兄"
    }
    },"sort": [
    {
    "age": {
    "order": "desc"
    }
    }
    ],
    "aggs": {
    "group_by_age": {
    "terms": {
    "field": "age"
    }
    }
    }
    }

    #新建一个索引
    PUT /movie/_doc/1
    {
    "name":"Eating an apple a day & keeps the doctor away"
    }

    GET /movie/_search
    {
    "query": {
    "match": {
    "name": "appl"
    }
    }
    }

    #使用analyze api查看分词状态 过滤两次(1.量词,特殊字符 2.词干 英文会大写变小写方便查询)
    GET /movie/_analyze
    {
    "field": "name",
    "text":"Eating an apple a day & keeps the doctor away"
    }

    DELETE /movie

    #使用结构化方式创建索引

    PUT /movie
    {
    "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
    },
    "mappings": {
    "properties": {
    "name":{"type": "text","analyzer": "english"}
    }
    }
    }

    GET /movie/_search

    #Text 被分析索引的字符串类型
    #keyword不能被分析只能被精确匹配的字符串类型
    #Date日期类型,可以配合format一起使用
    #数字类型 long interger short double
    #boolean true false
    #Array one two
    #Object json嵌套
    #IP 类型
    #Geo_point地址位置

  • 相关阅读:
    论单页Web应用和RESTful架构
    [译]作为一个web开发人员,哪些技术细节是在发布站点前你需要考虑到的
    JavaScript模块化规范
    一个Option请求引发的深度解析
    读《JavaScript语言精粹》的一些感言
    深圳积分入户经验之谈
    windows下的node-canvas历程
    linux服务器部署.net core 3.1
    Windows下Redis的安装、配置
    Linux Centos 安装宝塔面板一句命令解决
  • 原文地址:https://www.cnblogs.com/yaohaitao/p/12443435.html
Copyright © 2020-2023  润新知