Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Create Mapping and Add data in Elasticsearch

Everytime I follow the instruction about Create Index, Mapping and Add Data in elasticsearch i have the error. I'm using Postman. First of all, i create index:

POST http://localhost:9200/schools

(actually, i have to use put to create succesfully)

Next, i create Mapping and Add Data:

POST http://localhost:9200/schools/_bulk

Request Body

    {
       "index":{
          "_index":"schools", "_type":"school", "_id":"1"
       }
    }
    {
       "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
       "city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
       "fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
    }
    {
       "index":{
          "_index":"schools", "_type":"school", "_id":"2"
       }
    }
    {
       "name":"Saint Paul School", "description":"ICSE 
       Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075",
       "location":[28.5733056, 77.0122136], "fees":5000,
       "tags":["Good Faculty", "Great Sports"], "rating":"4.5"
    }
    {
       "index":{"_index":"schools", "_type":"school", "_id":"3"}
    }
    {
       "name":"Crescent School", "description":"State Board Affiliation", "street":"Tonk Road", 
       "city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922, 75.7923988],
       "fees":2500, "tags":["Well equipped labs"], "rating":"4.5"
    }

But all i receive is just:

   {
      "error": {
        "root_cause": [
          {
            "type": "json_e_o_f_exception",
            "reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 2, column: 3]"
          }
        ],
        "type": "json_e_o_f_exception",
        "reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@681c6189; line: 2, column: 3]"
      },
      "status": 500
    }
like image 531
trungducng Avatar asked Mar 03 '17 08:03

trungducng


People also ask

How do I enable dynamic mapping in Elasticsearch?

You enable dynamic mapping by setting the dynamic parameter to true or runtime . You can then use dynamic templates to define custom mappings that can be applied to dynamically added fields based on the matching condition: match_mapping_type operates on the data type that Elasticsearch detects.

How do you update a mapping field in Elasticsearch?

It is not possible to update the mapping of an existing field. If the mapping is set to the wrong type, re-creating the index with updated mapping and re-indexing is the only option available. In version 7.0, Elasticsearch has deprecated the document type and the default document type is set to _doc.

How do I push data into Elasticsearch?

The steps are as follows: Install Logstash via your package manager or by downloading and unzipping the tgz/zip file. Install the Logstash rss input plugin, which allows for reading RSS data sources: ./bin/logstash-plugin install logstash-input-rss.


2 Answers

This is because your request body JSON is malformed. I'd advise checking with just one entry until you can get it into Elasticsearch, then add the others.

The following JSON is valid, though I'm not sure if it provides the structure you want:

{
   "index":{
      "_index":"schools", "_type":"school", "_id":"1"
   },
   "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",
   "city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],
   "fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
}

You can use a tool for formatting and validating JSON to make sure it is valid JSON. Below are some examples.

http://jsonformatter.org/

https://jsonformatter.curiousconcept.com/

like image 120
Donglecow Avatar answered Oct 12 '22 15:10

Donglecow


I see something which similar to my problem. My problem solved!

Elasticsearch Bulk API - Unexpected end-of-input: expected close marker for ARRAY

like image 42
trungducng Avatar answered Oct 12 '22 15:10

trungducng