ElasticSearch常用api

------Create 增


POST /索引/类型/ID
{
   //参数

}

curl -XPOST 'http://hdp-1:9200/search2/article2/1' -H 'Content-Type: application/json' -d '{
  "title": "Test1",
  "tags" : "test",
  "summary" : "test",
  "content" : "test1 content",
  "pubtime":"0"
}'
curl -XPOST 'http://hdp-1:9200/search2/article2/2' -H 'Content-Type: application/json' -d '{
  "title": "Test2",
  "tags" : "test2",
  "summary" : "test2",
  "content" : "test2 content2",
  "pubtime":"2"
}'

返回结果

{"_index":"search2","_type":"article2","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

------Update 修改
POST /索引/类型/ID
{

   //参数
  }
 

curl -XPOST 'http://hdp-1:9200/search2/article2/1' -H 'Content-Type: application/json' -d '{
  "title": "Test1(updated)",
  "tags" : "test",
  "summary" : "test",
  "content" : "test1 content",
  "pubtime":"0"
}'
 

{"_index":"search2","_type":"article2","_id":"99","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}


------Query 查询
-----根据ID查询
GET /索引/类型/ID
 

curl -XGET 'http://hdp-1:9200/search2/article2/1'

结果:
{"_index":"search2","_type":"article2","_id":"99","_version":2,"found":true,"_source":{
  "title": "Test1(updated)",
  "tags" : "test",
  "summary" : "test",
  "content" : "test1 content",
  "pubtime":"0"
}}
--- 查询所有

curl -XGET 'http://hdp-1:9200/search2/article2/_search' -H 'Content-Type: application/json' -d '{
  "query" : {
    "match_all" : { }
  }
}'

--- 复杂查询

curl -XGET 'http://hdp-1:9200/search/article/_search' -H 'Content-Type: application/json' -d '{
"query": { 
    "bool": {
      "must": [
        { "match": { "title": "标题"}},
        { "match": { "tags": "标签" }}
      ],
      "filter": [ 
         { "range": { "pubtime": { "gte": "1000" }}}
      ]
    }
  }
}'

注:最好用英文,汉字有时找不到

----删除


DELETE /索引/类型/ID

curl -XDELETE 'http://hdp-1:9200/search2/article2/1'

使用Kibana进行交互操作

GET /student/banji/1
 
GET /student/banji/1?_source=title
 
GET /student/banji/_search
{
  "query" : {
    "bool" : {
        "filter" : {
           "term" : {
              "status" : "ok"
            }
          }
      }
  }
}
 
GET _search
{
  "query": {
    "match_all": {}
  }
}
 
GET search/article/_search
{
	"query": {
    "match_all": {}
  }
}
 
GET search/article/_search
{
"query": { 
    "bool": {
      "must": [
        { "match": { "title": "标题"}},
        { "match": { "tags": "标签" }}
      ],
      "filter": [ 
         { "range": { "pubtime": { "gte": "1000" }}}
      ]
    }
  }
}
 
GET search/article/_search
{
"query": { 
    "bool": {
      "must": [
        { "match": { "title": "标题"}},
        { "match": { "tags": "标签" }}
      ]
    }
  }
}
 
GET search/article/_search
{
"query": { 
    "bool": {
      
      "filter": [ 
         { "range": { "pubtime": { "gte": "60" }}}
      ]
    }
  }
}
 
GET search/article/_search
{
"query": { 
    "bool": {
      "must": [
        { "match": { "title": "标题"}},
        { "match": { "tags": "标签" }}
      ],
      "filter": [ 
         { "range": { "pubtime": { "gt": "60" }}}
      ]
    }
  }
}
 
GET search/article/_search
{
"query": { 
    "bool": {
      "must": [
        { "match": { "title": "标题"}},
        { "match": { "tags": "标签" }}
      ],
      "filter": [ 
         { "range": { "pubtime": { "gte": "60" }}}
      ]
    }
  }
}
 
POST search/article/3
{
  "title": "标题3",
  "tags" : "标签3",
  "content" : "内容3",
  "author" : "作者3",
  "pubtime":10000
}
 
 
 
POST search/article/2
{
  "title": "标题2",
  "tags" : "标签2",
  "content" : "内容2",
  "author" : "作者2",
  "pubtime":100
}
 
POST student/banji/3
{
  "title":"3班",
  "num":"55",
  "status":"ok"
}
 
PUT /ecommerce/product/1
{
    "name" : "gaolujie yagao",
    "desc" :  "gaoxiao meibai",
    "price" :  30,
    "producer" :      "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
}
GET /student

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值