如何从ElasticSearch

时间:2016-06-07 10:54:24

标签: elasticsearch

使用以下查询创建索引。弹性搜索正在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”:“Birmingham”,“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”}}

1 个答案:

答案 0 :(得分:2)

您需要输入元数据字段,然后输入数据字段。 理想情况下,文本文件应按以下格式保存数据

{ "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}}