搜索所有內容
# curl -XGET 'http://localhost:9200/_search?pretty' # curl -XGET 'http://localhost:9200/_all/_search?pretty'
指定 _index 搜索
# curl -XGET 'http://localhost:9200/website/_search?pretty' # curl -XGET 'http://localhost:9200/website/news/_search?pretty'
指定 _type 搜索
# curl -XGET 'http://localhost:9200/website,twitter/_search?pretty' # curl -XGET 'http://localhost:9200/website/news,blog/_search?pretty' # curl -XGET 'http://localhost:9200/website,twitter/news,blog/_search?pretty'
所有 _index 包含指定 _type 搜索
# curl -XGET 'http://localhost:9200/_all/news,blog/_search?pretty'
該功能與SQL的LIMIT關鍵字結果一樣,Elasticsearch接受size和from兩個參數參數:
size: 返回結果集數量,預設10,用法與SQL中的 Limit相同
from: 偏移量,預設0,用法與 SQL中的 Offset相同
如果你想每頁顯示10個結果,那麼請求如下:
第一頁 GET /_search?size=10 第二頁 GET /_search?size=10&from=10 第三頁 GET /_search?size=10&from=20
# curl -XGET 'http://localhost:9200/_all/_search?q=neo&pretty'
同時滿足兩個條件
+name:neo +age:30
查找name為mary 或者 john的數據
+name:(mary john)
查詢姓名是neo或者jam並且年齡小於30歲同時1980-09-10之後出生的
+name:(neo jam) +age:<30 +date:>1980-09-10
curl -XGET 'http://localhost:9200/information/news/_search?pretty' -d ' { "query" : { "match" : { "tag" : "美" } } } '
multi_match 實現多欄位查詢
curl -XGET 'http://localhost:9200/information/news/_search?pretty' -d ' { "query": { "multi_match": { "query": "國際", "type": "cross_fields", "fields": [ "title", "content" ], "operator": "and" } }, "from": 0, "size": 20, "_source":["id","title","ctime"], "sort": [ { "ctime": {"order": "desc"} } ] } '
curl -XGET 'http://localhost:9200/information/news/_search?pretty' -d ' { "query" : { "match" : {"tag" : "美"} }, "sort": { "ctime": {"order": "desc", "mode": "min"} } } '
curl -XGET 'http://localhost:9200/information/news/_search?pretty' -d ' { "query" : { "match" : { "tag" : "美" } }, "_source":["id","title","ctime"] } ' curl -XGET 'http://localhost:9200/information/news/_search?pretty' -d ' { "_source":["id","title","ctime"], "query" : { "match" : {"tag" : "美"} }, "sort": { "ctime": {"order": "desc", "mode": "min"} } } '