公號:碼農充電站pro
主頁:https://codeshellme.github.iohtml
ES 中的查詢 API 有兩種:git
經過 URI 能夠指定在哪些索引中進行查詢,有下面幾種格式:github
/_search
:在全部的索引中進行搜索。/index_name/_search
:在 index_name
索引中進行搜索。/index1,index2/_search
:在 index1
和 index2
索引中進行搜索。/index*/_search
:在全部的以 index
爲前綴的索引中進行搜索。URI 查詢使用 HTTP GET 請求的方式,使用 q
指定查詢的內容,格式以下:shell
curl -XGET http://localhost:9200/index_name/_search?q=key:val
簡寫爲:json
GET /index_name/_search?q=key:val
其表示的含義是:在 index_name
索引中的全部文檔中,查詢 key
字段的值爲 val
的內容。app
Request Body 查詢可使用 GET 或 POST 方式,格式以下:curl
curl -XGET/POST http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d' { "query": { "match_all":{} } }'
簡寫爲:搜索引擎
POST index_name/_search { "query": { "match_all": {} } }
若是查詢成功,會返回以下格式的內容:url
返回的結果集會以 _score
評分進行排序,_score
評分指的是查詢的相關性。code
搜索的相關性有 3 種衡量指標:
在 ES 中能夠經過調整查詢的參數來改善搜素的查準率和查全率。
(本節完。)
推薦閱讀:
[ElasticSearch 安裝與運行](https://www.cnblogs.com/codeshell/p/14371473.html
Kibana,Logstash 和 Cerebro 的安裝運行
歡迎關注做者公衆號,獲取更多技術乾貨。