http://localhost:9200/?pretty
http://localhost:5601/app/marvel
http://localhost:9200/_plugin/head/
1 请求格式
curl -i -X<VERB> '<PROTOCOL>://<HOST>/<PATH>?<QUERY_STRING>' -d '<BODY>'
VERB : GET POST HEAD DELETE PUT
PROTOCOL : http / https
HOST : 127.0.0.1:9200 (例子)
PORT : 端口号9200
QUERY_STRING : 查询参数 _count _search
BODY : json串
'{
"query": {
"match_all":{}
}
}'
2 与关系型数据库对比
Relational DB -> Databases -> Tables -> Rows -> Columns
ElasticSearch -> Indices (目录) -> Types -> Documents -> Fields
3 http://127.0.0.1:9200/megacorp/employee/_search?q=last_name:Smith
megacorp : index (目录)
employee : type
q : parameter
4 Query DSL
curl -XGET 'http://127.0.0.1:9200/megacorp/employee/_search' -d '
{
"query":{
"filtered":{
"filter":{
"range":{
"age":{"gt":30}
}
}
},
"query":{
"match":{
"last_name":"Smith"
}
}
}
}'
5 短语查询 和 高亮查询
curl -XGET 'http://127.0.0.1:9200/megacorp/employee/_search' -d '
{
"query":{
"match_phrase":{
"last_name":"Smith"
}
},
"highlight":{
"fields"{
"about":{}
}
}
}'
6 分析和 aggregations(聚合,类似于group by)
curl -XGET 'http://127.0.0.1:9200/megacorp/employee/_search' -d '
{
"query":{
"match":{
"about":"rock climbing"
}
},
"aggs":{
"all_interests":{
"terms":{"fields":"interests"},
}
}
}'
curl -XGET 'http://127.0.0.1:9200/megacorp/employee/_search' -d '
{
"aggs":{
"all_interests":{
"terms":{"fields":"interests"},
"aggs":{
"avg_age":{
"avg":{
"field":"age"
}
}
}
}
}
}'