CodePredator
CodePredator

Reputation: 415

Elasticsearch : Index Mapping for integer array

I have defined the following index mapping for one of the documents:

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

When I try to index the following document :

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

I get the following exception :

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)

From this link http://www.elasticsearch.org/guide/reference/mapping/array-type/ , I believe there is no problem with the index mapping. What am I doing wrong?

Upvotes: 2

Views: 10493

Answers (2)

CodePredator
CodePredator

Reputation: 415

The issue is resolved. I was giving the index type name wrong in the rest api url, it should have been 'localhost:9200/test-app/favorites/_mapping';, I was giving it as localhost:9200/test-app/ratings/_mapping.

Upvotes: 0

kielni
kielni

Reputation: 4999

When you have a parent/child relationship, you need to specify the parent when indexing a child document. See the Elasticsearch docs here: http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/ You didn't say how you were indexing these; via curl it should look like this, where activity-id is the id of the parent document of this favorite:

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

Upvotes: 3

Related Questions