vachina
vachina

Reputation: 45

JSON formatting in Elasticsearch

Bit confused.

I'm using jackson to parse JSON strings into maps that will then be accepted in elasticsearch.

That works fine.

However due to the JSON specifications, all integers and other formats need to be sent through as a string - aka - "key":"value". But then elasticSearch sees them as strings, not numbers. Which makes totaling values like user ratings not possible when it should be trivial.

How can I use the JSON format to input numbers/integers into elasticsearch?

Is there a way around this?

Upvotes: 1

Views: 8156

Answers (1)

denov
denov

Reputation: 12698

You may need to create a mapping for your index.

Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:

  • which string fields should be treated as full text fields.
  • which fields contain numbers, dates, or geolocations.
  • whether the values of all fields in the document should be indexed into the catch-all _all field.
  • the format of date values.
  • custom rules to control the mapping for dynamically added fields.

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

If you already have a some existing data that you don't want to lose you'll need to reindex after updating your mapping. Due to how ES indexes data you can not change the type after it's been created.

https://www.elastic.co/blog/changing-mapping-with-zero-downtime https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html

Upvotes: 3

Related Questions