使用以下查询创建索引。 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'
'原因: Action /元数据行[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”}}
{“城市”:“移动设备”,“州”:“AL”,“位置”:{“lat”:“30.6943566”,“long”:“-88.0430541”}}
最佳答案
您需要先放置元数据字段,然后再放置数据字段。
理想情况下,文本文件应以以下格式保存数据
{ "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}}
关于elasticsearch - 如何从ElasticSearch中的文件导入GEO_TYPE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37677388/