輕量搜索
一個 GET
是相當簡單的,可以直接得到指定的文檔。 現在嘗試點兒稍微高級的功能,比如一個簡單的搜索!
第一個嘗試的幾乎是最簡單的搜索了。我們使用下列請求來搜索所有雇員:
GET /megacorp/employee/_search
可以看到,我們仍然使用索引庫 megacorp
以及類型 employee
,但與指定一個文檔 ID 不同,這次使用 _search
。返回結果包括了所有三個文檔,放在數組 hits
中。一個搜索默認返回十條結果。
{ "took": 6, "timed_out": false, "_shards": { ... }, "hits": { "total": 3, "max_score": 1, "hits": [ { "_index": "megacorp", "_type": "employee", "_id": "3", "_score": 1, "_source": { "first_name": "Douglas", "last_name": "Fir", "age": 35, "about": "I like to build cabinets", "interests": [ "forestry" ] } }, { "_index": "megacorp", "_type": "employee", "_id": "1", "_score": 1, "_source": { "first_name": "John", "last_name": "Smith", "age": 25, "about": "I love to go rock climbing", "interests": [ "sports", "music" ] } }, { "_index": "megacorp", "_type": "employee", "_id": "2", "_score": 1, "_source": { "first_name": "Jane", "last_name": "Smith", "age": 32, "about": "I like to collect rock albums", "interests": [ "music"