0

My initial mapping was

{
  "vehiclemodel": {
    "properties": {
      "price": {
        "type": "double"
      }
    }
  }
}

Later I updated the mapping with below

{
  "vehiclemodel": {
    "properties": {
      "price": {
        "type": "double",
        "fields": {
          "exShowroomPrice": {
            "type": "double"
          }
        }
      }
    }
  }
}

Now when I add Data1 it getting added, but when I add Data2 it throws below exception

Data1 :

{
  "price": 36992043     
}

Data2 :

{
  "price": {
    "exShowroomPrice": 36992043
  }
}

Exception :

{
    'index': {
        '_index': 'notes',
        '_type': 'vehiclemodel',
        '_id': 'fb85823a-021b-468c-91d9-8db5f001ee06',
        'status': 400,
        'error': {
            'type': 'mapper_parsing_exception',
            'reason': 'failed to parse [price]',
            'caused_by': {
                'type': 'json_parse_exception',
                'reason': 'Current token (START_OBJECT) not numeric, can not use numeric value accessors\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@6e2393ee; line: 1, column: 277]'
            }
        }
    }
}

My collectionvehiclemodel has both type of data in MongoDB. I am using mongo-connector to sync data btw mongo and ES. When I try to sync I get the above exception

Shreyas Rao B
  • 193
  • 4
  • 17

2 Answers2

1

Your mapping is not correct for what I assume you want to achieve.

The fields mapping allows you to index the same field with different analyzers for example (see the linked docs for details). So in your case, you would push

{
    "price" : 1923
}

and ES will store it twice, once as price and once under the path price.exShowroomPrice.

You could just add a completely separate property, the hierarchy does not need to be maintained. For example a mapping like:

{
    "vehiclemodel": {
        "properties": {
            "price": {
                "type": "double"
            },
            "exShowroomPrice": {
                "type": "double"
            }
        }
    }
}

And then send the data like:

{
    "price" : 1923
    "exShowroomPrice" : 1800
} 

I don't know how mongo-connector works, but there should be a way to map these fields I would assume.

Slomo
  • 1,224
  • 8
  • 11
  • Here `exShowroomPrice` is a separate field. In my case I want `exShowroomPrice` as nested under `price` and also I want both **Data1** and **Datat2** need to be inserted. Here is the [link](https://stackoverflow.com/questions/40301061/elasticsearch-5-mapperparserexception-with-multi-field) which I refered to update my mapping – Shreyas Rao B Aug 04 '17 at 13:54
  • 1
    Probably impossible, because in Data1 `price` is a double, and in Data2 it is an object. – Slomo Aug 04 '17 at 14:05
0

Fields in elasticsearch mappings are thought to index the same field in different ways, such as processing the input field as a string or as a keyword. So you defined price as a double but elasticsearch finds an {} so this exception is thrown. You have to remodel your data there.

MartinSchulze
  • 889
  • 1
  • 7
  • 14