参考文献
Quick start | Elasticsearch Guide [7.17] | Elastic
单条新增
请求地址:http://localhost:9200/my_default/_doc
请求:post
请求参数:
{
"timestamp": "2099-05-06T16:21:15.000Z",
"event": {
"original": "192.0.2.42 click"
},
"name": "张19..",
"age": 19,
"year": 2000
}
获取映射
地址:http://localhost:9200/my_default/_mapping
请求:get
修改映射
地址:http://localhost:9200/my_default/_mapping
请求:put
{
"properties": {
"@timestamp": {
"type": "date"
},
"event": {
"properties": {
"original": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "date"
},
"age": {
"type": "long",
"index":false
},
"year": {
"type": "integer",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
映射说明--未完成部分
查询
查询排序
接口:http://localhost:9200/my_default/_search
请求:post
请求参数:
{
"query":{
"match":{
"name.keyword": "张15.."
}
},
"sort":[{
"age":"desc"
}]
}
查询fields
http://localhost:9200/my_default/_search
请求:post
请求参数:
{
"query":{
"match_all":{}
},
"fields":["name","age","timestamp"],
"sort":[{
"name.keyword":"desc"
}]
}
范围查询
地址:http://localhost:9200/my_default/_search
请求:post
请求参数:
{
"query":{
"range":{
"year":{
"gte":1998,
"lt":2000
}
}
},
"sort":{
"name.keyword":"desc"
}
}
联合查询
地址:http://localhost:9200/my_default/_search
请求:post
请求参数:
{
"query": {
"bool": {
"filter": [{
"range": {
"year": {
"gte": 1998,
"lt": 2000
}
}
},
{
"match": {
"name.keyword": "张16.."
}
}]
}
},
"sort": {
"name.keyword": "desc"
}
}
分页查询
url地址:http://localhost:9200/my_default/_search
请求:post
请求参数:
{
"from": 2,
"size": 10,
"query": {
"range": {
"year": {
"gte": 1998,
"lt": 2000
}
}
}
}