Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store Json field as String in Elastic search?

Tags:

I am trying to index a json field in elastic search, I have given it external mapping that this field should be treated as string and not json, also indexing is not required for it, so no need to analyze it. The mapping for this is following

"json_field": {
    "type": "string",
    "index": "no"
},

Still at the time of indexing, this field is getting analyzed and because of that I am getting MapperParsingException

in Short How can we store json as a string in elastic search without getting analyzed ?

like image 790
NIlesh Sharma Avatar asked Sep 16 '14 07:09

NIlesh Sharma


People also ask

Can JSON be stored as a string?

JSON exists as a string — useful when you want to transmit data across a network. It needs to be converted to a native JavaScript object when you want to access the data.

How do I import a JSON file into Elasticsearch?

To import a JSON file into Elasticsearch, we will use the elasticdump package. It is a set of import and export tools used for Elasticsearch. It makes it easier to copy, move, and save indexes. To install elasticdump , we will require npm and Node.

Does Elasticsearch use JSON?

Elasticsearch offers simple REST based APIs, a simple HTTP interface, and uses schema-free JSON documents, making it easy to get started and quickly build applications for a variety of use-cases.

Does Elasticsearch have schema?

Elasticsearch has the ability to be schema-less, which means that documents can be indexed without explicitly providing a schema. If you do not specify a mapping, Elasticsearch will by default generate one dynamically when detecting new fields in documents during indexing.


1 Answers

Finally got it, if you want to store JSON as a string, without analyzing it, the mapping should be like this

"json_field": {
    "type": "object",
    "enabled" : false
},

The enabled flag allows to disable parsing and indexing a named object completely. This is handy when a portion of the JSON document contains an arbitrary JSON which should not be indexed, nor added to the mapping.

Update - From ES version 7.12 "enabled" has been changed to "index".

like image 84
NIlesh Sharma Avatar answered Oct 13 '22 23:10

NIlesh Sharma