elasticsearch常见http请求示例

创建索引
curl -XPUT -H 'Content-Type: application/json' 'http://118.31.76.208:9200/test_index' -d 
 '{
      "settings":{
          "index":{
              "number_of_shards":3,
              "number_of_replicas":2
          }
      },
      "mappings":{
          "test_type":{
              "properties":{
                  "content":{
                      "type":"text"
                  }
              }
          }
      }
 }'
删除索引
   curl -XDELETE 'http://118.31.76.208:9200/test_index
插入数据
curl -XPUT -H 'Content-Type:application/json' 'http://118.31.76.208:9200/test_index/test_type/1001' -d 
   '{
     "content":"公安部:各地校车将享最高路权"
    }'
根据ID检索
 curl -XGET -H 'Content-Type:application/json' 'http://118.31.76.208:9200/test_index/test_type/1001'
文本检索
curl -XPOST -H 'Content-Type:application/json' 'http://118.31.76.208:9200/test_index/_search' -d 
   '{
     "query": 
     {
         "match":
         {
             "content" : "公安"
         }
      }
 }'
范围查询
curl -XGET -H 'Content-Type:application/json' 'http://10.0.35.148:9200/test_index/_search' -d '{
  "query":{
   "bool":{
    "filter":{
     "range":{
      "resolution.height":{
       "from":0,
       "to":1500,
       "include_lower":true,
       "include_upper":true
      }
     }
    }
   }
  }
 }'
修改索引设置
curl -XPOST -H 'Content-Type:application/json' 'http://118.31.76.208:9200/test_index/_setting' -d
   '{
      "index":{"refresh_interval":"60s"}
   }'
索引取别名
curl -XPOST -H 'Content-Type:application/json' 'http://10.0.35.148:9200/_aliases' -d 
 '{
  "actions" :[
   {
    "remove" : {
     "index" : "user_rec_index_20170928",
     "alias":"user_rec_index"
    }
   },
   {
    "add":{
     "index" : "user_rec_index_20180115",
     "alias":"user_rec_index"
    }
   }
  ]
 }'
设置评分脚本
curl -XPOST -H 'Content-Type:application/json' 'http://10.0.35.148:9200/_scripts/video_hot_score' -d 
   '{
       "script": 
       {
           "lang" : "painless", 
           "source" : "doc[\u0027hot_score\u0027].value"
       }
   }'
查询评分脚本
 curl -XGET -H 'Content-Type:application/json' 'http://10.0.35.148:9200/_scripts/video_hot_score'
查询时使用评分脚本
curl -XPOST -H 'Content-Type:application/json' 'http://118.31.76.208:9200/test_index/_search' -d 
 '{
  "query" : 
  {
   "script" :
   {
    "query" : {
     "match" : 
     {
      "field" : "content"
     }
    },
    "script" : {
     "id" : "video_hot_score",
     "params" : {
      "params1" : 1,
      "params2" : "haha"
     }
    }
   }
  }
 }'
function score
curl -XGET  -H 'Content-Type: application/json' 'http://10.0.35.148:9200/test_index/_search' -d '
 {
     "query": {
         "function_score": {
             "query": {
                 "match": { "description": "微视频" }
             },
             "script_score" : {
                 "script" : {
                     "params": {
                         "current": 1516008207380
                     },
                     "source": "doc[hot_score].value/((2+(current-doc[publish_time].value)/86400000.0)*1.7)+1"
                 }
             }
         }
     }
 }'
suggest
curl -XGET -H 'Content-Type:application/json' 'http://10.0.35.148:9200/test_index/_search' -d '{
   "suggest" : {
     "suggest" : {
       "text" : "舞蹈",
       "completion" : {
         "field" : "tags.suggest",
         "size" : 10
       }
     }
   }
 }'

你可能感兴趣的:(数据挖掘)