elasticsearch上的映射格式

时间:2015-09-08 18:02:23

标签: json indexing elasticsearch mapping

我要通过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”}
}'

2 个答案:

答案 0 :(得分:1)

这是因为您正在使用start_list = [5, 3, 1, 2, 4] square_list = [] square_list.append(start_list) square_list.sort() for start_list in square_list: print square_list 端点来安装映射。

您必须使用_search端点,如下所示:

_mapping

答案 1 :(得分:1)

这里有一些问题。首先,您需要使用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"}}'

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