0

I use elasticsearch-river-jdbc to import data from mysql,and i have a string field ,the data in this field is a json string(like this:'[{"id":1}]'),i want to mapping the string to object in elasticsearch,anyone known how to do this?

I use the type_mappping to mapping the field :

"type_mapping":
  {
      "postsInfo":
          {"properties":
            {
                "forums":{
                    "type":"object"
                }
            }
          }
  }

but elasticsearch throw a exception:

org.elasticsearch.index.mapper.MapperParsingException: object mapping for [postsInfo] tried to parse field [forums] as object, but got EOF, has a concrete value been provided to it?
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:495)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:544)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:493)
at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:480)
at org.elasticsearch.action.bulk.TransportShardBulkAction.shardIndexOperation(TransportShardBulkAction.java:423)
at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:149)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:515)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:422)
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:745)

and i have google for a long time,but didn't found out a solution,can anyone help me?

the document that cause the exception:

{
"postsId":100,
"gmtCreate":"2015-08-17T16:38:54.000+08:00",
"gmtModified":"2015-12-10T19:38:17.000+08:00",
"status":1,
"postsType":1,
"title":"test",
"userId":123,
"userIconPath":"/user/avatar/123.png",
"province":null,
"city":null,
"district":null,
"recommendCover":null,
"location":{
    "lat":0,
    "lon":0
},
"lat":null,
"lng":null,
"forums":"[{"id":18,"name":"官方"}]",
"subForums":"[{"id":19,"name":"评测"}]",
"isDeleted":0,
"weight":0,
"dayGroup":"2015-08-17",
"content":"test"

}

jason.lin
  • 1
  • 1
  • The following answer should help you: http://stackoverflow.com/questions/32452979/elasticsearch-and-jdbc-mapping-analyzer-filter-setup/32470275#32470275 – Val Jan 12 '16 at 04:48
  • my type-mapping is under jdbc ,the problem is that elasticsearch can not mapping json string to object,my json string is a array(like this '[{"id":1},{"id":2}]') ,but elasticsearch do not have array type, i use object type,i throw a exception – jason.lin Jan 12 '16 at 04:58
  • According to your error, one of the documents doesn't have any `forums` object. – Val Jan 12 '16 at 04:59
  • some of the document's forums is null ,is this cause the exception? – jason.lin Jan 12 '16 at 05:02
  • Yes, probably. at least try to make it an empty object `{}` – Val Jan 12 '16 at 05:03
  • i have try only one document ,and the forums is not null, but get the same exception – jason.lin Jan 12 '16 at 05:05
  • Can you update your question with that document, please? – Val Jan 12 '16 at 05:07
  • i update the question already – jason.lin Jan 12 '16 at 05:18
  • `forums` is a string (i.e. enclosed in double quotes) not an object, fix that and it will work :-) – Val Jan 12 '16 at 06:11

0 Answers0