#查看所有索引 curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/_cat/indices?v' #查询索引下所有文档 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": { "match_all": {} }}' #查询索引下所有文档,并返回第一个文档 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": { "match_all": {} },"size":1}' #匹配所有并返回第1到10 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": { "match_all": {} },"from": 0,"size": 10}' #根据属性降序排序(size未指定默认为10) curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": { "match_all": {} },"sort": {"status": { "order": "desc" }}}' #返回name和status这2个fields(_source里),相当于sql:SELECT name, status FROM.... curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": { "match_all": {} },"_source": ["name", "status"]}' #返回status为1的,相当于sql的WHERE curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": { "match": { "status": 1 } }}' #返回type=77 && status=1的文档 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": {"bool": {"must": [{ "match": { "type": 77 } },{ "match": { "status": 1 } }]}}}' #返回type=77 || status=1的文档 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": {"bool": {"should": [{ "match": { "type": 77 } },{ "match": { "status": 1 } }]}}}' #返回type=77 非 status=1的文档 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": {"bool": {"must_not": [{ "match": { "type": 77 } },{ "match": { "status": 1 } }]}}}' #返回type是134但status不是2的 curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"query": {"bool": { "must": [{ "match": { "type": 134 } }],"must_not": [{ "match": { "status": 2 } }]}}}' # 相当于sql: SELECT COUNT() from bank GROUP BY state ORDER BY COUNT() DESC。 #「size=0」是设置不显示search hit curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"size": 0,"aggs": {"group_by_state": {"terms": {"field": "status"}}}}' #按state分组并计算(组)平均balance(默认返回前10个按state的COUNT的降序(DESC)排) curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/yuntu_poi_index_7/_search?pretty' -d '{"size": 0,"aggs": {"group_by_state": {"terms": {"field": "status"},"aggs": {"average_balance": {"avg": {"field": "type"}}}}}}'
创建索引