参考,es的mapping和字段类型 :https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html
参考,logstash的fileter插件:https://www.elastic.co/guide/en/logstash/current/filter-plugins.html
参考,es 的地理查询:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html
ES设置mapping
PUT poi-003
{
"mappings": {
"properties": {
"@timestamp":{
"type": "date"
},
"@version":{
"type":"keyword"
},
"name":{
"type": "text",
"fields": {
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"address":{
"type": "text",
"fields": {
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"typecode":{
"type": "text",
"fields": {
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"x":{
"type": "float"
},
"y":{
"type": "float"
},
"location":{
"type": "geo_point"
}
}
}
}
logstash的配置文件
input {
stdin { }
file {
path => ["/home/aganliang/es/downloads/logstash-7.6.2/myconfig/data/poi-3.json"]
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
json {
source => "message"
# target => "poi"
remove_field =>["message"]
}
mutate {
remove_field => ["path","host"]
add_field => ["[location][lat]", "%{y}"]
add_field => ["[location][lon]", "%{x}"]
}
}
output {
elasticsearch {
index => "poi-003"
hosts => ["localhost:9200"]
}
stdout {
codec => rubydebug
}
}
kibana中测试地理查询
POST poi-003/_search
{
"query": {
"bool": {
"filter": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 24.258,
"lon": 112.254
},
"bottom_right": {
"lat": 22.258,
"lon": 114.258
}
}
}
}
}
}
}