标签:读书笔记 text tags copies 深入 new test elasticsearch type
es基本查询
- 添加索引
put /new_test
{
"mappings": {
"properties": {
"author": {
"type": "text"
},
"characters": {
"type": "text"
},
"copies": {
"type": "long"
},
"otitle": {
"type": "text"
},
"tags": {
"type": "keyword"
},
"title": {
"type": "text"
},
"year": {
"type": "long"
},
"available": {
"type": "boolean"
},
"review": {
"type": "nested",
"properties": {
"nickname": {
"type": "text"
},
"text": {
"type": "text"
},
"stars": {
"type": "integer"
}
}
}
}
}
}
- 批量插入数据
post /new_test/_bulk
{ "index" : { "_id" : "1" } }
{"title":"All Quiet on the Western Front","otitle":"Im Westen nichts Neues","author":"Erich Maria Remarque","year":1929,"characters":["Paul Bäumer","Albert Kropp","Haie Westhus","Fredrich Müller","Stanislaus Katczinsky","Tjaden"],"tags":["novel"],"copies":1,"available":true,"section":3}
{"index":{"_id":"2"}}
{"title":"Catch-22","author":"Joseph Heller","year":1961,"characters":["John Yossarian","Captain Aardvark","Chaplain Tappman","Colonel Cathcart","Doctor Daneeka"],"tags":["novel"],"copies":6,"available":false,"section":1}
{"index":{"_id":"3"}}
{"title":"The Complete Sherlock Holmes","author":"Arthur Conan Doyle","year":1936,"characters":["Sherlock Holmes","Dr. Watson","G. Lestrade"],"tags":[],"copies": 0, "available":false, "section":12}
- 查询[1,3]区间的数据
get /new_test/_search
{
"query":{
"range":{
"copies":{
"gte":1,
"lte":3
}
}
}
}
- 找出所有至少有一本的书籍,并对1950年后出版的书籍进行加权
get /new_test/_search
{
"query":{
"bool":{
"must":[{"range":{"copies":{"gte":1}}}],
"should":[{"range":{"year":{"gt":1950}}}]
}
}
}
- 查找出所有tags字段包含novel值的书籍
get /new_test/_search
{
"query":{
"term":{
"tags":"novel"
}
}
}
- 前缀查询
get /new_test/_search
{
"query":{
"prefix":{
"title":"qu"
}
}
}
- 匹配短语
get /new_test/_search
{
"query":{
"match_phrase":{
"otitle":"nichts"
}
}
}
标签:读书笔记,text,tags,copies,深入,new,test,elasticsearch,type 来源: https://www.cnblogs.com/Baronboy/p/15343528.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。