繁体   English   中英

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...
}'

这里有一些问题。 首先,您需要使用放置映射请求而不是搜索请求。 请求的主体必须以类型的名称开头,后跟要添加的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"}}'

请注意,要添加映射,如果您已经尝试向该索引添加文档并且已经创建映射,则可能需要删除并重新创建索引。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM