ElasticSearch常用请求笔记

新增索引

PUT - http://localhost:9200/qpyx-search-word?pretty=true
{
    "settings" : {
        "index" : {
            "number_of_shards" : 3, 
            "number_of_replicas" : 2 
        }
    },  
    "mappings" : {
            "dynamic": false,
            "properties" : {
                "ip":{
                    "type" : "text"
                },  
                "search_word":{
                    "type":"text",
                    "analyzer": "whitespace",
                   "search_analyzer": "whitespace",
                    "fielddata": true #可根据   
                },  
                "create_time":{
                    "type":"date",
                    "format":"yyyy-MM-dd HH:mm:ss.SSS"
                }
            }
    }
}

删除索引

DELETE - http://localhost:9200/qpyx-search-word?pretty=true

编辑索引

PUT - localhost:9200/qpyx-search-word/_mapping
{
  "properties": {
    "search_word": { 
      "type":     "text",
      "analyzer": "whitespace",
      "search_analyzer": "whitespace",
      "fielddata": true
    }
  }
}

查询信息

普通查询

GET - localhost:9200/qpyx-search-word/_search
{
     "query": {
          "range": {
              "create_time": {
                "gte": "now-3d/d"
              }
        }
     },
     "sort": [
          {
               "create_time": {
                    "order": "desc"
               }
          }
     ]
}

根据字段数量展示(热搜)

GET - localhost:9200/qpyx-search-word/_search
{
    "size": 0,
    "from": 0,
    "query": {
        "range": {
              "create_time": {
                "gte": "now-3d/d"
              }
        }
    },
    "aggs": {
        "group-msg": {
            "terms": {
                "field" : "search_word",
                "size" : 5
            }
        }
    }
}
原文地址:https://www.cnblogs.com/zhaww/p/13901722.html