简体   繁体   English

Elasticsearch的映射格式

[英]Mapping format on elasticsearch

I'm to upload a json document to my server via elasticsearch but i wanted to map it before i upload it but i keep getting a search phase execution exception error. 我打算通过elasticsearch将json文档上传到我的服务器,但是我想先映射它,然后再上传,但是我一直收到搜索阶段执行异常错误。 The json data looks like this json数据看起来像这样

{"geometry":{"type":"Point","coordinates":[-73.20266100000001,45.573647]},"properties":{"persistent_id":"XVCPFsbsqB7h4PrxEtCU3w==","timestamp":1408216040000,"tower_id":"10.48.66.178"}}

So far i've tried this as my mapping. 到目前为止,我已经尝试过将其作为映射。 Im not sure what i am doing wrong... 我不确定我在做什么错...

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

This is because you're using the _search endpoint in order to install your mapping. 这是因为您使用_search端点来安装映射。

You have to use the _mapping endpoint instead, like this: 您必须改为使用_mapping端点,如下所示:

curl –XPUT 'http://localhost:9200/carrier/_mapping/geometry' -d '{
    ...your mapping...
}'

There are a few problems here. 这里有一些问题。 First of all you need to use put mapping request instead of search request. 首先,您需要使用放置映射请求而不是搜索请求。 The body of the request has to start with the name of the type followed by the list of properties (fields) that you add. 请求的主体必须以类型的名称开头,后跟要添加的properties (字段)列表。 The second problem is that you probably copied the example from some documentation where all ascii quotes ( " ) were replaced with replaced with their fancy unicode versions ( and ) and dash in front of the XPUT parameter looks like n-dash instead of normal dash - . You need to replace all fancy quotes and dashes with their ascii versions. So, all together the working statement should look like this (assuming doc as your document type): 第二个问题是您可能从某些文档中复制了该示例,在该文档中,所有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"
                    }
                }
            }

        }
    }
}'

then you can add document like this: 那么您可以像这样添加文档:

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

Please note that in order to add the mapping you might need to delete and recreate the index if you already tried to add documents to this index and the mapping was already created. 请注意,要添加映射,如果您已经尝试向该索引添加文档并且已经创建映射,则可能需要删除并重新创建索引。

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

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