ElasticSearch配置

2016-03-11  本文已影响144人  Jevirs

ElasticSearch配置

概念

安装运行

//普通用户身份操作(解压)curl -L -O 
https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.0.0/elasticsearch-2.0.0.tar.gz
...
...
tar -xvf elasticsearch-2.0.0.tar.gzcd elasticsearch-2.0.0/bin./elasticsearch
...
...

占用9200端口,对文档操作提供REST API

curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>
//exp
curl -XGET 'localhost:9200/index/type/id?pretty'
curl -XPUT 'localhost:9200/index/type/1' -d '{ "name": "John Doe"}'
curl -XDELETE 'localhost:9200/customer'

CRUD语法- 查询

curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{ "query": { "match-all": { } }, //所有文档 
"query": { "match": { "address": "mill" } }, //特定文档
"query": { "match": { "address": "aaa bbb" } }, //含有aaa或bbb "query": { "match_phrase": { "address": "aaa bbb" } }, //含有"aaa bbb"
"size":10, //记录条数 
"from":10, //记录跳页
"sort": { "balance": { "order": "desc" } },//排序
//与 
"query": { 
  "bool": {  
   "must": [ { "match": { "address": "mill" } },
             { "match": { "address": "lane" } } 
    ]
  } 
}, 
//或 
"query": { 
  "bool": { 
    "should": [ 
      { "match": { "address": "mill" } }, 
      { "match": { "address": "lane" } }
     ]
   }
 },
 //非 
"query": { 
  "bool": {
     "must_not": [
       { "match": { "address": "mill" } },
       { "match": { "address": "lane" } }
       ]
     }
 }, 
//多条件 
"query": { 
  "bool": {
     "must": [
       { "match": { "age": "40" } } ],
     "must_not": [ 
        { "match": { "state": "ID" } }
       ]
   }
  },
 //范围选择 
"query": {  
  "bool": { 
     "must": { "match_all": {} },
     "filter": {  
        "range": { 
          "balance": {"gte": 20000,"lte": 30000} 
        }
     }
   } 
}, 
 //排序 
"aggs": { 
  "group_by_state": {
       "terms": { "field": "state" } 
    }
   } 
}
上一篇下一篇

猜你喜欢

热点阅读