0

How do I create a document in elastic search? I am using curl to create a document. However, I get the following error

{"error":"MapperParsingException[failed to parse]; nested:  JsonParseException[Unexpected character (''' (code 39)): expected a valid value (number, String,    array, object, 'true', 'false' or 'null')\n at [Source: [B@39312db4; line: 1, column: 2]]; ","status":400}

This is the CURL command

curl -XPUT localhost:9200/hello1/equipment/1 -d '{"hi":"val1"}'
2
  • 2
    Is this is the exact line that you are using? It works fine for me. Which version of elasticsearch are you using and on which operating system do you run this command? Commented Sep 9, 2015 at 1:49
  • Windows 8 and elasticsearch version 1.7.1 Commented Sep 9, 2015 at 16:14

2 Answers 2

3

there is no need to create index and mapping separately for this. I think you are trying to create by command line (cmd prompt of windows etc).

use this statement:

curl -XPUT "http://localhost:9200/hello1/equipment/1" -d"{\"hi\":\"val1\"}"

In cmd prompt quoting character is " hence in place of ' you will have to use double quotes to quote and inside the json body you have to escape your double quotes using \ to tell prompt not to treat them as quotes.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't have enough reputation to publicly upscore yet.I have accepted it but will not show publicly now.
here refer this if you have any query regarding answer acceptance. meta.stackoverflow.com/questions/251078/…
Hey do you know logstash or anyone who know it well?. Could you help me with this stackoverflow.com/questions/32321704/… help would be appreciated
1

You should try this by enclosing single inverted comma 'http://localhost:9200/hello1/equipment/1' instead of localhost:9200/hello1/equipment/1....It should work!

So appropriate way to create document is, First of all you need to create an index, So in your case in order to put document steps are following:

Create an index

curl -XPUT 'http://localhost:9200/hello1'

Create an mapping ( If you won't provide, it will create dynamically)

curl -XPUT 'http://localhost:9200/hello1/equipment/_mapping' -d '{"equipment":{"text":{"type":string}}"}'

Putting document

curl -XPUT 'http://localhost:9200/hello1/equipment/1' -d '{"hi":"val1"}'

1 Comment

Putting document this way doesn't work for me using command line in Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.