zoukankan      html  css  js  c++  java
  • Es 常用搜索

    查看索引mapping

    GET /ybyl_area_analysis/_mapping

     

    删除索引

    DELETE ybyl_award

     

    新增映射

    PUT /ybyl_award/_mapping

    {

      "properties": {

        "lbs_md5": {

          "type": "keyword"

        }

      }

    }

    查看某个字段的映射

    GET /ybyl_award/_mapping/field/lbs_md5

     

    #清空文档

    POST /ybyl_behavior/_delete_by_query

    {

      "query": {

        "match_all": {}

      }

    }

     

     

    批量搜索

    GET /ybyl_award/_msearch

    {}

    {"query":{"match":{"code":"308602c5667773d8b69cdeea46cd1233"}}}

    {"index":"ybyl_behavior"}

    {"query":{"match":{"code":"308602c5667773d8b69cdeea46cd1233"}}}

     

     

    批量操作

    POST /customer/_bulk?pretty

    {"index":{"_id":"4"}}

    {"name":"Hua 1","age":15}

    {"index":{"_id":"5"}}

    {"name":"Hua 2","age":17}

     

     

    POST /customer/_bulk?pretty

    {"update":{"_id":"4"}}

    {"doc":{"name":"Hua 11","age":"34"}}

    {"delete":{"_id":"5"}}

     

    删除文档id=4

    DELETE /customer/_doc/4?pretty

     

    更新文档,不存在则添加

    POST /customer/_doc/4?pretty

    {

      "name":"Zhun.li",

      "age":32

    }

     

     

    更新文档, 只更新指定字段 1

    POST /customer/_update/1?pretty

    {

      "doc":{

        "name":"bing_test"

      }

    }

     

    更新文档, 只更新指定字段 2

    POST /customer/_update/1?pretty

    {

      "script":"ctx._source.age += 5"

    }

     

    搜索全部——排序

    【from + size 文档上限 1W】

    GET /customer/_search

    {

      "query": {

        "match_all": {}

      },

      "sort": [

        {

          "age": {

            "order": "asc"

          }

        },

    {

          “Id”: {

            "order": "asc"

          }

        }

      ],

      "from": 0,

      "size": 2

    }

    搜索 区间搜索

    GET /test_award/_search

    {

      "query":{

        "range": {

          "update_time": {

            "gte":1590480655

          }

        }

      }

    }

     

     

    搜索, 多个must match  

    GET /test_award/_search

    {

      "query": {

        "bool": {

          "must": [

            {“term”: {

              "wx_openid": "7608b030db4dbc1d43760fd21e2a4bf1"

            }},

            {“term”:{

              "award_type":"1"

            }}

            ]

          }

        },

      "from": 0,

      "size": 1000

    }

     

    搜索like“ and “in”, 按多个区间进行过滤

     

    GET /test_award/_search

    {

      "query": {

        "bool": {

          "must": [

            {

              "match": {

                "wx_openid": "7608b030db4dbc1d43760fd21e2a4bf1"

              }

            },

            {

              "terms": {

                "award_type": [

                  "1",

                  "3"

                ]

              }

            }

          ],

          "filter": [{

            "range": {

              "create_time": {

                "gte": 1590422400,

                "lte": 1590508799

              }

            }

          },{

            "range": {

              "update_time": {

                "gte": 1590422400,

                "lt": 1590489014

              }

            }

          }]

        }

      },

      "from": 0,

      "size": 1000

    }

     

     

    Scoll滚动搜索,  "sort": [ "_doc" ] 会按_id(字符串)顺序排序

    GET /ybyl_award/_search?scroll=1m

    {

      "query": {

        "match":{

          "wx_openid":"qDHprQMf+pbmcjKELsN0QATNmAAZFVxrvRaS3ZGMCmM="

        }

      },

      "sort": [ "_doc" ],

      "size": 2

    }

     

    GET /_search/scroll

    {

      "scroll": "1m",

      "scroll_id": "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAY75cWQml4S0lzVWJRcS1XRl9hcGVTc1ZDUQ=="

    }

     

     

     

    lbs坐标范围搜索 - geo_distance

    GET /test_award/_search

    {

      "query": {

        "bool": {

          "must": [{

            "geo_distance": {

              "distance": "1m", 

              "lbs": { 

                "lon": "116.408296",

                "lat": "39.934962"

              }

            }

          },

          {"terms":{

              "award_type":[1,2,3]

            }

          }

          ],

          "must_not":{

            "term":{

              "award_name":"谢谢参与"

            }

          }

        }

      }

    }

     

     

    聚合搜索 aggs count(*)

    【不指定size值,默认只显示10个】

    #Where count(*) group by field

    POST /ybyl_award/_search

    {

      "query": {

        "bool": {

          "must_not":{

            "term":{

              "award_name":"谢谢参与"

            }

          },

          "filter":{

            "range":{

              "award_time":{

                "lte":1591302574

              }

            }

          }

        

        }

      },

      "aggs": {

        "award_name": {

          "terms":{

            "field":"award_name”,

    "size":20

          }

        }

      }

    }

     

    聚合搜索 aggs sum(field)

    # sum(field2) group by field1

    GET /ybyl_area_analysis/_search

    {

      "query": {

        "match_all": {}

      },

      "aggs":{

        "city":{

          "terms":{

            "field":"city"

          },

          "aggs":{

            "total":{

              "sum":{

                "field":"award_num"

              }

            }

          }

        }

      }

    }

  • 相关阅读:
    多线程
    事务的概念与四大特性(ACID)
    Error和Exception的区别
    运算符的使用与注意事项(二)
    运算符的使用与注意事项(一)
    GOJS使用--前端拓扑图
    python算法实现分治法demo
    MySQL主从复制配置
    MySQL锁
    show profile查看SQL执行生命周期
  • 原文地址:https://www.cnblogs.com/bandbandme/p/13255698.html
Copyright © 2011-2022 走看看