【问题标题】:How to import GEO_TYPE from file in ElasticSearch如何从 ElasticSearch 中的文件导入 GEO_TYPE
【发布时间】:2025-11-26 03:30:01
【问题描述】:

使用以下查询创建索引。 Elastic Search 正在 Windows 上运行。

curl -XPUT http://localhost:9200/us_large_cities -d  "{"""mappings""": {"""city""": {"""properties""": {"""city""": {"""type""": """string"""},"""state""": {"""type""": """string"""},"""location""": {"""type""": """geo_point"""}}}}}"

使用以下命令创建文档。

curl -XPOST http://localhost:9200/us_large_cities/city/ -d "{"""city""": """Birmingham""", """state""": """AL""","""location""": {"""lat""": """33.5206608""", """lon""": """-86.8024900"""}}"

使用命令一切正常。但是当我想使用下面的查询使用 json 文件导入数据时。

curl -XPOST localhost:9200/us_large_cities/city/_bulk?pretty --data-binary "@citylocation.txt"

它给了我错误。

'错误类型:Illegal_argumaent_exception'

'原因:动作/元数据行 [1] 格式错误,应为 START_OBJECT 或 END_OBJECT,但发现 [VALUE STRING]

我的文件数据是:

{"city": "伯明翰", "state": "AL","location": {"lat" : "33.5206608", "long" : "-86.8024900"}}

{"city": "Huntsville", "state": "AL","location": {"lat" : "34.7303688", "long" : "-86.5861037"}}

{"city": "Mobile", "state": "AL","location": {"lat" : "30.6943566", "long" : "-88.0430541"}}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您需要放置元数据字段,然后是数据字段。 理想情况下,您的文本文件应保存以下格式的数据

    { "index" : { "_index" : "us_large_cities", "_type" : "city" } }
    {"city": "Birmingham", "state": "AL","location": {"lat" : 33.5206608, "long" : -86.8024900}}
    { "index" : { "_index" : "us_large_cities", "_type" : "city" } }
    {"city": "Mobile", "state": "AL","location": {"lat" : 30.6943566, "long" : -88.0430541}}
    

    【讨论】:

    • 谢谢先生,现在它给了我错误'归档必须是 [lat] , [long] 或 [geohash]'..
    • 当我使用以下格式时,它成功插入了值。 {“索引”:{“_index”:“us_large_cities”,“_type”:“城市”}} {“城市”:“伯明翰”,“州”:“AL”,“位置”:[33.5206608,-86.8024900] } { "index" : { "_index" : "us_large_cities", "_type" : "city" } } {"city": "Mobile", "state": "AL","location": [30.6943566,-88.0430541 ]} 想知道您的解决方案有什么问题,为什么它给我们例外..
    • lat 和 long 在您给我的示例中作为字符串给出。应该一样长。
    最近更新 更多