当前位置: 首页 > 知识库问答 >
问题:

不能在Elasticsearch 5和Kibana 5中使用GeoJSON

祁飞扬
2023-03-14

我无法在Elasticsearch中索引GeoJSON数据并用它们创建平铺地图。

-->将GeoJSON发送到ES:

curl -XPUT "http://localhost:9200/datas/data/3617" -d 
'{
    "geometry": {
        "coordinates": [
            7.040691666666667,
            43.626736111111114
        ],
        "type": "Point"
    },
    "properties": {
        "createdAt": {
            "$date": "2016-04-06T15:40:42.402Z"
        },
        "device": "000-0002",
        "ind": 0,
        "timestamp": {
            "$date": "2016-04-06T16:40:41.000Z"
        }
    },
    "type": "Feature"
}'

curl-xget“http://localhost:9200/datas/data/_mapping”

{
  "datas": {
    "mappings": {
      "data": {
        "properties": {
          "geometry": {
            "properties": {
              "coordinates": {
                "type": "float"
              },
              "type": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "properties": {
            "properties": {
              "createdAt": {
                "properties": {
                  "$date": {
                    "type": "date"
                  }
                }
              },
              "device": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "ind": {
                "type": "long"
              },
              "timestamp": {
                "properties": {
                  "$date": {
                    "type": "date"
                  }
                }
              }
            }
          },
          "type": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}
curl -XPUT "http://localhost:9200/datas/_mapping/data" -d '{
    "data": {
       "properties": {
          "geometry": {
             "type": "geo_shape"
          }
       }
    }
  }'

=>{“已确认”:true}

$ curl -XGET "http://localhost:9200/datas/_mapping/data"

=>{“datas”:{“mappings”:{“data”:{“properties”:{“geometry”:{“type”:“geo_shape”}}}}}}}

curl -XPUT "http://localhost:9200/datas/data/3617" -d 
'{
    "geometry": {
        "coordinates": [
            7.040691666666667,
            43.626736111111114
        ],
        "type": "Point"
    },
}'

=>{“_index”:“datas”,“_type”:“data”,“_id”:“3617”,“_version”:1,“_shards”:{“total”:2,“successed”:1,“failed”:0},“created”:true}

在映射中将geo_shape替换为geo_point时,插入示例数据时出现以下错误:

curl -XPUT "http://localhost:9200/datas/data/3617" -d 
'{
    "geometry": {
        "coordinates": [
            7.040691666666667,
            43.626736111111114
        ],
        "type": "Point"
    },
}'

{"error":{"root_cause":[{"type":"parse_exception","reason":"field must be either [lat], [lon] or [geohash]"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"parse_exception","reason":"field must be either [lat], [lon] or [geohash]"}},"status":400}

共有1个答案

凌俊语
2023-03-14

ES不直接摄取GeoJSON,相反,您需要将其转换为适当的geo_shape,在您的示例中,它将是一个

首先,您需要创建一个索引和一个映射来接受geo_shape字段,如下所示:

curl -XPUT "http://localhost:9200/datas" -d '{
  "mappings": {
    "data": {
       "properties": {
          "location": {
             "type": "geo_shape"
          }
       }
    }
  }
}'

然后您可以像这样索引您的GeoJSON点:

curl -XPUT "http://localhost:9200/datas/data/3617" -d '{
    "location" : {
        "type" : "point",
        "coordinates" : [7.040691666666667, 43.626736111111114]
    }
}'
curl -XPUT "http://localhost:9200/datas" -d '{
  "mappings": {
    "data": {
       "properties": {
          "location": {
             "type": "geo_point",
             "geohash_prefix": true
          }
       }
    }
  }
}'

curl -XPUT "http://localhost:9200/datas/data/3617" -d '{
    "location" : {
        "lat": 43.626736111111114,
        "lon": 7.040691666666667
    }
}'
 类似资料:
  • 我试图用Java(在Fedora 27上)创建一个测试JSON验证器,但是我不能导入与JSON相关的包。不同的Java实现是否为此使用不同的包? 我的源代码如下: 错误日志: jsonParsing.java:2:错误:包javax.json不存在,导入javax.json.json;^jsonParsing.java:3:错误:包javax.json不存在,导入javax.json.jsonOb

  • 问题内容: 这是我的代码,用于在用户忘记密码的情况下重置用户密码。数据通过AJAX请求发送到PHP代码,PHP代码根据输入的有效性简单地回显“ Y”或“ N”。 问题是,AJAX调用在Firefox 19和IE 9中不起作用。我没有在其他版本的IE中尝试过。AJAX调用可在chrome和safari中完美运行。有人遇到过同样的问题吗?有人可以帮忙吗? 问题答案: 您必须使用事件对象作为事件处理程序

  • 本文向大家介绍windows7系统安装elasticsearch5.X,包括了windows7系统安装elasticsearch5.X的使用技巧和注意事项,需要的朋友参考一下 一、安装jdk ElasticSearch是基于lucence开发的,也就是运行需要java jdk支持。所以要先安装JAVA环境。 由于ElasticSearch 5.x 往后依赖于JDK 1.8的,所以现在我们下载JDK

  • 问题内容: 我使用Flask-Login 在模板中提供对象。我想编写一个宏来显示评论表单或登录链接,具体取决于用户是否登录。如果我直接在模板中使用此代码,它将起作用: 我将相同的代码放在宏中,然后将宏导入模板中。 当我尝试加载此页面时,出现的错误是: 当然,简单的解决方法是current_user作为参数传递并使用该参数(进行签名comment_form(user, form)),尽管这是一个非常

  • 我有一个非常简单的类,它是一个Restful web服务。我想在web服务中使用EJB。我使用@EJB注释来注入我的EJB。唯一的问题是,EJB总是空的。然后我使我的web服务本身成为一个无状态EJB。这修复了空问题。但是,当我试图调用EJB上的任何函数时,我得到以下错误: 编辑:这里是CasperLoggingDao的代码

  • 我试图测试一个@Controller类,其中有来自POJO的列表。我可以在另一个@RESTController类中使用@Autowired来连接控制器,但在同样的情况下,我不能将其用于测试。 user.java UserContrell3.java 在下一个类中,userresource.java我可以做@autowired 但是,在测试类UserTest.java中。我不能: 提前感谢!