您的位置:首页 > 产品设计 > UI/UE

Elasticsearch.The.Definitive.Guide学习笔记 -- 1. You know, for search

2016-10-19 16:11 573 查看
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"
}
}
}
}
}
}'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elastic search