1. 程式人生 > >elasticsearch基本Restful操作

elasticsearch基本Restful操作

delet 查詢 數據 content app rest HR restfu bin

1、添加數據
curl -H "Content-Type: application/json" -XPUT ‘http://localhost:9200/megacorp/employee/3‘ -d‘
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}‘;

2、刪除數據
curl -XDELETE ‘http://localhost:9200/megacorp/employee/1‘

3、查看記錄
curl -XGET ‘http://localhost:9200/megacorp/employee/1‘

4、查看所有記錄
curl -XGET ‘http://localhost:9200/megacorp/employee/_search‘

5、簡單條件查詢
curl -XGET ‘http://localhost:9200/megacorp/employee/_search?q=last_name:Smith‘

6、match 查詢法
curl -H "Content-Type: application/json" -XGET ‘http://localhost:9200/megacorp/employee/_search‘ -d‘
{
"query" : {
"match" : {
"about" : "rock climbing"
}
}
}‘

7、短語搜索(匹配若幹個單詞或者短語)
curl -H "Content-Type: application/json" -XGET ‘http://localhost:9200/megacorp/employee/_search‘ -d‘
{
"query" : {
"match_phrase": {
"about": "rock climbing"
}
}
}‘


8、結構化搜索的限定條件 filter(過濾器)
curl -XGET ‘http://localhost:9200/megacorp/employee/_search‘ -d‘
{
"query" : {
"filtered" : {
"filter" : {
"range" : {
"age" : { "gt" : 30 } <1>
}
},
"query" : {
"match" : {
"last_name" : "Smith" <2>
}
}
}
}
}

elasticsearch基本Restful操作