ElasticSearch 常用命令

获取前5条记录

/jrtt/shehui/_search

获取前N条记录

/jrtt/shehui/_search?size=N

匹配查询

POST /jrtt/shehui/_search  
{
  "query": {
    "term" : { "title" : "权力的游戏第八季剧透 剧情剧本曝光 维斯特洛大陆上发生了什么" } 
  }
}

获取Index记录总条数

/jrtt/shehui/_count

删除所有记录

POST /jrtt/_delete_by_query  
{
    "query" : { 
        "match_all" : {}
    }
}

删除匹配的记录

{ "query": 
    { "match": 
        {"source": 7} 
    } 

}

删除Mapping

DELETE /jrtt/  

创建mapping

PUT /jrtt/  
{
  "mappings": {
    "shehui" : {
      "properties" : {       
        "title" : {
          "type" :   "string",
          "index":"not_analyzed"
        },
        "content" : {
          "type" :   "string"
        },
        "upload": {
          "type": "text",
          "fielddata": true
        }
      } 
    }
  }
}

查找一定时间范围内并且满足关键字的记录

{
  "query": { 
    "bool": { 
      "filter": [ 
        { "term":  { "chanid" : "1002" }}, 
        { "range": { "upload" : {
                "gt" : 1505716552984,
                "boost" : 5.0
            }}} 
      ]
    }
  }
}