elasticsearch上的映射格式
Mapping format on elasticsearch
我要通过 elasticsearch 将 json 文档上传到我的服务器,但我想在上传之前对其进行映射,但我一直收到搜索阶段执行异常错误。
json 数据看起来像这样
{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}
到目前为止,我已经尝试将此作为我的映射。我不确定我做错了什么...
curl –XPUT 'http://localhost:9200/carrier/_search?q=coordinates?pretty=true' -d'
{ “geometry”: {
“type” : {“type” : “string”},
“coordinates” : {“type” : “geo_point”}
},
“properties” : {
“persistent_id” : {“type” : “string”},
“timestamp”: { “type” : “long”},
“tower_id” : {“type” : “string”}
}'
这是因为您正在使用 _search
端点来安装映射。
您必须改用 _mapping
端点,如下所示:
curl –XPUT 'http://localhost:9200/carrier/_mapping/geometry' -d '{
...your mapping...
}'
这里有一些问题。首先,您需要使用 put mapping 请求而不是搜索请求。请求的主体必须以类型名称开头,后跟您添加的 properties
(字段)列表。第二个问题是您可能从一些文档中复制了示例,其中所有 ascii 引号 ("
) 都被替换为他们花哨的 unicode 版本 (“
和 ”
) 和前面的破折号XPUT
参数看起来像 n-dash –
而不是普通的破折号 -
。您需要用它们的 ascii 版本替换所有花哨的引号和破折号。因此,所有工作语句应该如下所示(假设 doc
作为您的文档类型):
curl -XPUT 'http://localhost:9200/carrier/doc/_mapping' -d '{
"doc": {
"properties": {
"geometry": {
"properties": {
"type": {
"type": "string"
},
"coordinates": {
"type": "geo_point"
}
}
},
"properties": {
"properties": {
"persistent_id": {
"type": "string"
},
"timestamp": {
"type": "long"
},
"tower_id": {
"type": "string"
}
}
}
}
}
}'
然后你可以这样添加文档:
curl -XPUT 'http://localhost:9200/carrier/doc/1' -d '{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}'
请注意,如果您已尝试将文档添加到此索引并且映射已创建,则为了添加映射,您可能需要删除并重新创建索引。
我要通过 elasticsearch 将 json 文档上传到我的服务器,但我想在上传之前对其进行映射,但我一直收到搜索阶段执行异常错误。 json 数据看起来像这样
{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}
到目前为止,我已经尝试将此作为我的映射。我不确定我做错了什么...
curl –XPUT 'http://localhost:9200/carrier/_search?q=coordinates?pretty=true' -d'
{ “geometry”: {
“type” : {“type” : “string”},
“coordinates” : {“type” : “geo_point”}
},
“properties” : {
“persistent_id” : {“type” : “string”},
“timestamp”: { “type” : “long”},
“tower_id” : {“type” : “string”}
}'
这是因为您正在使用 _search
端点来安装映射。
您必须改用 _mapping
端点,如下所示:
curl –XPUT 'http://localhost:9200/carrier/_mapping/geometry' -d '{
...your mapping...
}'
这里有一些问题。首先,您需要使用 put mapping 请求而不是搜索请求。请求的主体必须以类型名称开头,后跟您添加的 properties
(字段)列表。第二个问题是您可能从一些文档中复制了示例,其中所有 ascii 引号 ("
) 都被替换为他们花哨的 unicode 版本 (“
和 ”
) 和前面的破折号XPUT
参数看起来像 n-dash –
而不是普通的破折号 -
。您需要用它们的 ascii 版本替换所有花哨的引号和破折号。因此,所有工作语句应该如下所示(假设 doc
作为您的文档类型):
curl -XPUT 'http://localhost:9200/carrier/doc/_mapping' -d '{
"doc": {
"properties": {
"geometry": {
"properties": {
"type": {
"type": "string"
},
"coordinates": {
"type": "geo_point"
}
}
},
"properties": {
"properties": {
"persistent_id": {
"type": "string"
},
"timestamp": {
"type": "long"
},
"tower_id": {
"type": "string"
}
}
}
}
}
}'
然后你可以这样添加文档:
curl -XPUT 'http://localhost:9200/carrier/doc/1' -d '{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}'
请注意,如果您已尝试将文档添加到此索引并且映射已创建,则为了添加映射,您可能需要删除并重新创建索引。