Elasticsearch:整数数组的索引映射

时间:2013-09-27 15:58:21

标签: arrays indexing integer elasticsearch

我为其中一个文档定义了以下索引映射:

{
   "favorites":{
      "_parent":{
         "type":"activities"
      },
      "properties":{
         "favorite_count":{
            "type":"integer"
         },
         "details":{
            "type":"integer",
            "store":"yes"
         }
      }
   }
}

当我尝试索引以下文档时:

{
      "favorite_count":3,
      "details":[
          1, 25, 4
      ]
}

我得到以下异常:

org.elasticsearch.index.mapper.MapperParsingException: object mapping [details] trying to serialize a value with no field associated with it, current value [1]
    at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:595)
    at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:467)
    at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:599)
    at org.elasticsearch.index.mapper.object.ObjectMapper.serializeArray(ObjectMapper.java:587)
    at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:459)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:507)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:451)
    at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:329)
    at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:203)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:521)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:419)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

从这个链接http://www.elasticsearch.org/guide/reference/mapping/array-type/,我相信索引映射没有问题。我做错了什么?

2 个答案:

答案 0 :(得分:2)

如果您有父/子关系,则需要在索引子文档时指定父级。请参阅此处的Elasticsearch文档:http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/您没有说明您是如何编制索引的;通过curl它应该看起来像这样,其中activity-id是这个最喜欢的父文档的id:

curl -XPOST localhost:9200/favorites?parent=activity-id -d'
{
      "favorite_count":3,
      "details":[
          1, 25, 4
      ]
}'

答案 1 :(得分:0)

问题已解决。我在其余的api url中给出了索引类型名称错误,它应该是'localhost:9200 / test-app / favorites / _mapping';,我将它作为localhost:9200 / test-app / ratings / _mapping。