1, data preparation
PUT /lib3 { "settings":{ "number_of_shards":3, "number_of_replicas":0 }, "mappings":{ "user":{ "properties":{ "name":{"type":"text"}, "address":{"type":"text"}, "age":{"type":"integer"}, "interests":{"type":"text"}, "birthday":{"type":"date"} } } } }
put /lib3/user/1 { "name":"zhaoliu", "address":"hei long jiang sheng tie ling shi", "age":50, "birthday":"1970-12-12", "interests":"xi huang hejiu,duanlian,lvyou" } put /lib3/user/2 { "name":"zhaoming", "address":"bei jing hai dian qu qing he zhen", "age":20, "birthday":"1998-10-12", "interests":"xi huan hejiu,duanlian,changge" } put /lib3/user/3 { "name":"lisi", "address":"bei jing hai dian qu qing he zhen", "age":23, "birthday":"1998-10-12", "interests":"xi huan hejiu,duanlian,changge" } put /lib3/user/4 { "name":"wangwu", "address":"bei jing hai dian qu qing he zhen", "age":26, "birthday":"1998-10-12", "interests":"xi huan biancheng,tingyinyue,lvyou" } put /lib3/user/5 { "name":"zhangsan", "address":"bei jing chao yang qu", "age":29, "birthday":"1988-10-12 " , " Interests " : " XI Huan tingyinyue, Changge, tiaowu " }
2, the query
GET / lib3 / user / _search q = name:? Lisi lisi query name is recorded
GET / lib3 / user / _search q = interests:? Changge & sort = age: desc queries interest include singing, sorted by age and reverse
term, terms inquiries:
term query will go to the inverted index to find the exact term, it does not know the word's existence, this query for keyword, numeric, date.
Archie a field contains a keyword: term
(1) the query name is zhaoliu:
GET /lib3/user/_search/ { "query":{ "term":{"name":"zhaoliu"} } }
(2) interest include query drinking or singing:
get /lib3/user/_search { "query":{ "terms":{ "interests":["hejiu","changge"] } } }
(3) the query interest comprising alcohol or singing, from index 0, remove the two:
get /lib3/user/_search { "from":0, "size":2, "query":{ "terms":{ "interests":["hejiu","changge"] } } }