添加程序員
PUT /megacorp/employee/1 { "first_name" : "John", "last_name" : "Smith", "age" : 25, "about" : "I love to go rock climbing", "interests": [ "sports", "music" ] }
獲取編程
GET /megacorp/employee/1
簡單搜索ide
GET /megacorp/employee/_search
簡單條件搜索rest
GET /megacorp/employee/_search?q=last_name:Smith
條件搜索ip
GET /megacorp/employee/_search { "query" : { "match" : { "last_name" : "Smith" } } }
更復雜的搜索it
GET /megacorp/employee/_search { "query" : { "bool": { "must": { "match" : { "last_name" : "smith" } }, "filter": { "range" : { "age" : { "gt" : 10 } } } } } }
全文搜索ast
GET /megacorp/employee/_search { "query" : { "match" : { "about" : "rock climbing" } } }
再添加一個class
PUT /megacorp/employee/2 { "first_name" : "張", "last_name" : "三", "age" : 24, "about": "一個PHP程序員,熱愛編程,熱愛生活,充滿激情。", "interests": [ "英雄聯盟" ] }
高亮搜索cli
GET /megacorp/employee/_search { "query" : { "match_phrase" : { "about" : "rock climbing" } }, "highlight": { "fields" : { "about" : {} } } }
{ "took": 114, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.5753642, "hits": [ { "_index": "megacorp", "_type": "employee", "_id": "1", "_score": 0.5753642, "_source": { "first_name": "John", "last_name": "Smith", "age": 25, "about": "I love to go rock climbing", "interests": [ "sports", "music" ] }, "highlight": { "about": [ "I love to go <em>rock</em> <em>climbing</em>" ] } } ] } }
獲取數量搜索
GET /megacorp/employee/_count { "query": { "match" : { "last_name" : "Smith" } } }