Update a particular field in ES 2.4.0 document? - elasticsearch

I have document like this
"College": "UCLA",
"University": "American",
"Branch": "MECH",
"Name": {
"first": "john",
"middle": "william",
"last": "Richards"
}
I have to update the last field in Name group
I tried with the following but it is showing error
POST alma/matter/1/_update
{
"doc": { "Name.last": "junior" }
}
Error:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Field name [Name.last] cannot contain '.'"
}
],
"type": "mapper_parsing_exception",
"reason": "Field name [Name.last] cannot contain '.'"
},
"status": 400
}

You're not allowed to reference fields with dots in them. You can do it like this instead:
POST alma/matter/1/_update
{
"doc": { "Name": {"last": "junior" }}
}

Related

elasticsearch mapping issue: failed to parse field

I have this mapping
PUT /mytest
{
"mappings":{
"properties": {
"value": { "type": "object" }
}
}
}
When I insert this document
POST /mytest/_doc/4
{
"value": { "value": "test"}
}
I got the following error:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse field [value.value] of type [long] in document with id '4'. Preview of field's value: 'test'"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse field [value.value] of type [long] in document with id '4'. Preview of field's value: 'test'",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "For input string: \"test\""
}
},
"status": 400
}
I know the naming convention is bad, still, this is a valid JSON request, not sure why it doesn't allow it.
This error is telling you that you don't have a mapping for the property value within your value object property. The below example would property set the value.value property within your mytest index:
PUT mytest
{
"mappings": {
"properties": {
"value": {
"type": "object",
"properties": {
"value": {
"type": "text"
}
}
}
}
}
}
However, I don't think that's what your intention was. As a best practice, try following the Elastic Common Schema (ECS) for naming your index properties.

Elastic Search scaled float not accepting data

Following is the mapping for the index index_new
{
"mappings": {
"_doc": {
"properties": {
"title": {
"type": "text"
},
"name": {
"type": "text"
},
"age": {
"type": "integer"
},
"price_amount": {
"properties": {
"val": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
}
}
}
While adding the data to this index
curl -X POST \
http://localhost:9200/new_index1/1 \
-H 'Content-Type: application/json' \
-d '{
"title": "new data for index",
"name": "balakarthik",
"age": 24,
"price_amount": {
"val": 1005,
"scaling_factor": 100
}
}'
this returns an error
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Field [val] misses required parameter [scaling_factor]"
}
},
"status": 400
}
As the scaling factor is already provided in the mapping do we need to send the scaling factor in each requests, if so then how we need to send the scaling factor in each requests.
Definition for scaled_float is available here
I encountered this error but got past it by changing the URL.
Your PUT should go to: http://localhost:9200/new_index1/_doc/1
Also, you should change your input data to only specify the value. Something like this:
{
"title": "new data for index",
"name": "balakarthik",
"age": 24,
"price_amount": 10.05
}

Elasticsearch percolate mapping error

I want to use percolate query in elasticsearch. But I couldn't setup mapping. I have received the following error. where is my fault?
PUT /my-index
{
"mappings": {
"doctype": {
"properties": {
"message": {
"type": "string"
}
}
},
"queries": {
"properties": {
"query": {
"type": "percolator"
}
}
}
}
}
Error Message:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "No handler for type [percolator] declared on field [query]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [queries]: No handler for type [percolator] declared on field [query]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "No handler for type [percolator] declared on field [query]"
}
},
"status": 400
}
Thanks

failed to parse timestamp elasticsearch

I'm new to elasticsearch and am trying to create my first index but am having issues with a timestamp field that was working before...
I created my index like this:
PUT /kafkasdp
{
"mappings": {
"kafka_logs": {
"properties": {
"timestamp": {
"type": "date"
},
"log_level": {
"type": "string"
},
"message1": {
"type": "string"
},
"message2": {
"type": "string"
}
}
}
}
}
and then I'm trying to send data like this:
post /kafkasdp/kafka_logs
{
"timestamp": "2017-02-03 19:27:20,606",
"log_level": "INFO",
"message2": "Deleting segment 1 from log omega-replica-sync-dev-8. (kafka.log.Log)"
}
but keep getting this error:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse [timestamp]"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse [timestamp]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Invalid format: \"2017-02-03 19:27:20,606\" is malformed at \" 19:27:20,606\""
}
},
"status": 400
}
I thought my timestamp is a valid date type?
Read about date type on Elasticsearch reference: you should specify format of date you are expecting in your documents:
PUT your_index_name
{
"mappings": {
"your_index_type": {
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss,SSS"
}
}
}
}
}
As you did not specify it, Elasticsearch will expect date value in ISO format:
yyyyMMdd'T'HHmmss.SSS'Z' (e.g., 2017-02-03T19:27:20.606Z)

Getting error in Elasticsearch while creating index using postman

I have installed Elasticsearch 5.1 in ubuntu 14.04. I have performed some operations in Elasticsearch like create index, delete index etc. Then I have installed Kibana 5.1. Now I want to create new index in elasticsearch using postman (localhost:9200/my_index with PUT). But I'm getting this error.
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.country] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
],
"type": "illegal_argument_exception",
"reason": "unknown setting [index.country] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
},
"status": 400
}
I remember that I have used country as index or type. But then I have purged elasticsearch and kibana (also deleted directories related to those). Reinstalled both. But still getting this error. If anyone knows the solution, it will be appreciated.
Here is output of some query which may you need to solve issue.
GET localhost:9200/_mapping
{ ".kibana": {
"mappings": {
"server": {
"properties": {
"uuid": {
"type": "keyword"
}
}
},
"config": {
"properties": {
"buildNum": {
"type": "keyword"
}
}
}
} } }
(GET) localhost:9200/_cat/indices?v
[ {
"health": "yellow",
"status": "open",
"index": ".kibana",
"uuid": "O_ORG0ONQNCEe8JU_C0SKQ",
"pri": "1",
"rep": "1",
"docs.count": "1",
"docs.deleted": "0",
"store.size": "3.1kb",
"pri.store.size": "3.1kb" } ]
(GET) localhost:9200/country
{ "error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "country",
"index_uuid": "na",
"index": "country"
}
],
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "country",
"index_uuid": "na",
"index": "country" }, "status": 404 }
You can simply have a PUT request as such:
http://localhost:9200/indexname <--- give your index name
And then within your request body you could give the mappings:
{
"mappings": {
"message_logs": {
"properties": {
"anyfield": { <-- give your field
"type": "text" <-- and the type
}
}
}
}
}
This SO might help you if you're willing to create the index using CURL.
The above is just a sample. You could reproduce it.

Resources