一句话说服你用elasticsearch,“github用elasticsearch实时检索1300亿行代码”
bin/elasticsearch.yml
中的 cluster.name
和 node.name
,前者用来自动加入相同 cluster.name
的集群 bin/elasticsearch
启动,或者 bin/elasticsearch -d
以守护进程启动 http://localhost:9200
Create
: PUT /indexName/type/id {...}
如果url中不提供id,es会生成一个。同一个url如果PUT多次会累加 _version
,并且新的版本会替换老的版本 Update
: POST /indexName/type/id/_update {'doc':{'field':value}}
Delete
: DELETE url
Read
: GET url
POST /indexName/type/_bulk {"index":{"_id":n}/n{json}}
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}'
Post /indexName/type/_search
{
"query": {
"match":{
"field": keywords
}
},
"size":n
}
Get /indexName/type/_search
{
"query": {
"match_phrase":{
"field": keywords
}
},
"from":fromNo,
"size":n
}
Get /indexName/type/_search
{
"query": {
"bool":{
"must": [
"match": {
"field": keyword1
}
"match_phrase":{
}
]
}
}
}
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": { "match_all": {} },
"_source": ["account_number", "balance"]
}'
curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": {
"range": {
"balance": {
"gte": 20000,
"lte": 30000
}
}
}
}
}
}'