elasticsearch基本Restful操作


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>
}
}
}
}
}


原文链接:https://www.cnblogs.com/runnerjack/p/8484497.html