Elasticsearch multiple nested mapping error - elasticsearch

I create an index for Elasticsearch and update mapping for that index, while doing this I use the same mapping as there is because I have reasons for it.
However, for the following situation, an error is returning that I don't understand, am I doing something wrong?
Thanks.
CREATE INDEX (Successful)
PUT /mytestindex
{
"mappings": {
"properties": {
"variable1": {
"type": "nested",
"include_in_parent": true,
"include_in_root": true,
"properties": {
"variable2": {
"type": "double"
},
"variable3": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"variable4": {
"type": "double"
},
"variable5": {
"type": "nested",
"include_in_parent": true,
"include_in_root": true,
"properties": {
"variable6": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
UPDATE MAPPING AND RESPONSE
PUT /mytestindex/_mapping
{
"properties": {
"variable1": {
"type": "nested",
"include_in_parent": true,
"include_in_root": true,
"properties": {
"variable2": {
"type": "double"
},
"variable3": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"variable4": {
"type": "double"
},
"variable5": {
"type": "nested",
"include_in_parent": true,
"include_in_root": true,
"properties": {
"variable6": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
{
"error" : {
"root_cause" : [
{
"type" : "mapper_exception",
"reason" : "the [include_in_root] parameter can't be updated on a nested object mapping"
}
],
"type" : "mapper_exception",
"reason" : "the [include_in_root] parameter can't be updated on a nested object mapping"
},
"status" : 500
}

Related

Find documents that contain the specified elements in the array

I have a index with following mapping:
{
"error_message_1": {
"mappings": {
"dynamic": "strict",
"properties": {
"_class": {
"type": "keyword",
"index": false,
"doc_values": false
},
"message": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
},
"ngrams": {
"type": "text",
"analyzer": "autocomplete"
}
},
"copy_to": [
"myownfield"
]
},
"errorName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
},
"ngrams": {
"type": "text",
"analyzer": "autocomplete"
}
},
"copy_to": [
"myownfield"
]
},
"myownfield": {
"type": "text"
}
}
}
}
}
I have document with following body:
{
"_index": "error_message_1",
"_source": {
"id": 1,
"message": "message",
"errorName": "errorName"
},
When I tried to execute search with body:
{
"fields": ["myownfield"]
}
I got following result:
"fields": {
"myownfield": [ "message, "errorName"].
Then I have array with search params: ["message", "errorName"]. How can I get this document by query?

Unable to apply new index template

I am currently trying to update an index template on Elastic Search 6.7/6.8.
Templates are stored in the code and are applied each time my API starts.
There are no errors, the request returns 200.
For example, here is a template i am currently using:
{
"index_patterns": [ "*-ec2-reports" ],
"version": 11,
"mappings": {
"ec2-report": {
"properties": {
"account": {
"type": "keyword"
},
"reportDate": {
"type": "date"
},
"reportType": {
"type": "keyword"
},
"instance": {
"properties": {
"id": {
"type": "keyword"
},
"region": {
"type": "keyword"
},
"state": {
"type": "keyword"
},
"purchasing": {
"type": "keyword"
},
"keyPair": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"platform": {
"type": "keyword"
},
"tags": {
"type": "nested",
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
},
"costs": {
"type": "object"
},
"stats": {
"type": "object",
"properties": {
"cpu": {
"type": "object",
"properties": {
"average": {
"type": "double"
},
"peak": {
"type": "double"
}
}
},
"network": {
"type": "object",
"properties": {
"in": {
"type": "double"
},
"out": {
"type": "double"
}
}
},
"volumes": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"read": {
"type": "double"
},
"write": {
"type": "double"
}
}
}
}
},
"recommendation": {
"type": "object",
"properties": {
"instancetype": {
"type": "keyword"
},
"reason": {
"type": "keyword"
},
"newgeneration": {
"type": "keyword"
}
}
}
}
}
},
"_all": {
"enabled": false
},
"numeric_detection": false,
"date_detection": false
}
}
}
I'd like to add a new keyword field under the properties object like this :
"exampleField": {
"type": "keyword"
}
but it seems the template is not applied to existing indexes.
When data is inserted into a specific index which use the template, it is stored like this:
"exampleField": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
because the template has not been updated beforehand.
I would expect it to be like:
"exampleField": {
"type": "keyword"
}
in the index and in the template.
Does someone have any idea on how to have this result?
Thank you, Alexandre.

"unknown key [] for create index"

I am creating this Index, and I got an error.
I want to create an index of cities with names, people living, number of villages, facts about cities, etc.
My code is:
IMAGE OF MY CODE
PUT City-mk
{
"mappings": {
"properties": {
"CityID": {
"type": "integer"
},
"CityName": {
"type": "text",
"fields": {
"type": "keyword"
}
}
},
"People": {
"type":"integer"
},
"Fact": {
"type": "text",
"fields": {
"type": "keyword"
}
}
},
"Villages": {
"type": "integer"
},
"CallNum": {
"type": "integer"
}
}
You need to make following corrections:
Index name must be in lowercase, so change City-mk to city-mk
Braces count was wrong
Subfields were defined wrongly- "fields": { "keyword": { "type": "keyword" } }
PUT city-mk
{
"mappings": {
"properties": {
"CityID": {
"type": "integer"
},
"CityName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"People": {
"type": "integer"
},
"Fact": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"Villages": {
"type": "integer"
},
"CallNum": {
"type": "integer"
}
}
}
}

Cannot create mapping settings for an index with error message

I have been trying to do a mapping for an index and I am having these error messages.
By the way, I am using the latest version Elasticsearch - Kibana 6.7
I tried reading the documentation and tried editing the query but it is still not working.
PUT employee-details
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
}
},
"mappings": {
"doc": {
"dynamic": "strict",
"properties": {
"EmpUserID": {
"type": "integer"
},
"EmpName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"Age": {
"type": "integer"
},
"Gender": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"Address": {
"type": "nested",
"properties": {
"AddressID": {
"type": "integer"
}
},
"AddressNumber": {
"type": "integer"
},
"Location": {
"type": "object",
"properties": {
"LocationID": {
"type": "integer"
},
"LocationName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"LocationCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"AddressLine1": {
"type": "text",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"AddressLine2": {
"type": "text",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"CityName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"StateCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"StateName": {
"type": "text",
"analyzer": "my_analyzer",
"keyword": {
"type": "keyword"
}
},
"CountryName": {
"type": "text",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
},
"LastUpdateTimeStamp": {
"type": "date",
"format": "MM/dd/yyyy hh:mm a z",
"fields": {
"text": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
}
I'm getting this error message,
I don't know what happened with this one..
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Mapping definition for [Address] has unsupported parameters: [AddressNumber : {type=integer}] [Location : {type=object, properties={AddressLine2={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, AddressLine1={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, CountryName={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, StateName={analyzer=my_analyzer, type=text, keyword={type=keyword}}, LocationID={type=integer}, LocationCode={type=text, fields={keyword={type=keyword}}}, StateCode={type=text, fields={keyword={type=keyword}}}, CityName={type=text, fields={keyword={type=keyword}}}, LocationName={type=text, fields={keyword={type=keyword}}}}}]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [doc]: Mapping definition for [Address] has unsupported parameters: [AddressNumber : {type=integer}] [Location : {type=object, properties={AddressLine2={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, AddressLine1={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, CountryName={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, StateName={analyzer=my_analyzer, type=text, keyword={type=keyword}}, LocationID={type=integer}, LocationCode={type=text, fields={keyword={type=keyword}}}, StateCode={type=text, fields={keyword={type=keyword}}}, CityName={type=text, fields={keyword={type=keyword}}}, LocationName={type=text, fields={keyword={type=keyword}}}}}]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Mapping definition for [Address] has unsupported parameters: [AddressNumber : {type=integer}] [Location : {type=object, properties={AddressLine2={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, AddressLine1={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, CountryName={analyzer=my_analyzer, type=text, fields={keyword={type=keyword}}}, StateName={analyzer=my_analyzer, type=text, keyword={type=keyword}}, LocationID={type=integer}, LocationCode={type=text, fields={keyword={type=keyword}}}, StateCode={type=text, fields={keyword={type=keyword}}}, CityName={type=text, fields={keyword={type=keyword}}}, LocationName={type=text, fields={keyword={type=keyword}}}}}]"
}
},
"status": 400
}
You json has a few syntax mistakes. Here is the corrected one:
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}
}
}
},
"mappings": {
"doc": {
"dynamic": "strict",
"properties": {
"EmpUserID": {
"type": "integer"
},
"EmpName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"Age": {
"type": "integer"
},
"Gender": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"Address": {
"type": "nested",
"properties": {
"AddressID": {
"type": "integer"
},
"AddressNumber": { <---------- fields here on wards were outside nested properties block
"type": "integer"
},
"Location": {
"type": "object",
"properties": {
"LocationID": {
"type": "integer"
},
"LocationName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"LocationCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"AddressLine1": {
"type": "text",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"AddressLine2": {
"type": "text",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"CityName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"StateCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"StateName": {
"type": "text",
"analyzer": "my_analyzer",
"fields": { <---------- fields was missing here
"keyword": {
"type": "keyword"
}
}
},
"CountryName": {
"type": "text",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
},
"LastUpdateTimeStamp": { <--------- was outside properties block
"type": "date",
"format": "MM/dd/yyyy hh:mm a z",
"fields": {
"text": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
}
}

Defining Elasticsearch mapping for ingest-attachment inner field

I'm trying to build an application using an Elasticsearch index.
I have several "inner" fields which can contain binary data (mainly PDF), and I'm looking for the best way to define my pipeline and mapping, given the facts that:
all fields and contents can be provided in several languages (french and english) and in several fields
I have to be able to query contents for a given language and/or for a given field.
This is how I defined my mapping until now:
{
"WfNewsEvent": {
"properties": {
"title": {
"type": "object",
"properties": {
"en": {
"type": "string"
},
"fr": {
"type": "string",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
},
...
"extfile": {
"type": "object",
"properties": {
"title": {
"type": "object",
"properties": {
"en": {
"type": "string"
},
"fr": {
"type": "string",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
},
"description": {
"type": "object",
"properties": {
"en": {
"type": "string"
},
"fr": {
"type": "string",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
},
"data": {
"type": "object",
"properties": {
"en": {
"type": "attachment"
},
"fr": {
"type": "attachment",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
}
}
},
"gallery": {
"type": "object",
"properties": {
"title": {
"type": "object",
"properties": {
"en": {
"type": "string"
},
"fr": {
"type": "string",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
},
"description": {
"type": "object",
"properties": {
"en": {
"type": "string"
},
"fr": {
"type": "string",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
},
"data": {
"type": "object",
"properties": {
"en": {
"type": "attachment"
},
"fr": {
"type": "attachment",
"analyzer": "french",
"search_analyzer": "french_search"
}
}
}
}
}
}
}
}
Then my 'attachment' pipeline definition:
{
"description" : "Extract attachment information",
"processors" : [
{
"attachment" : {
"field" : "extfile.data.en",
"ignore_missing": true
}
},
{
"attachment" : {
"field" : "extfile.data.fr",
"ignore_missing": true
}
},
{
"attachment" : {
"field" : "gallery.data.fr",
"ignore_missing": true
}
},
{
"attachment" : {
"field" : "gallery.data.fr",
"ignore_missing": true
}
}
]
}
Actually when I'm trying to index a document, ES raises an exception saying that "data" is not an integer. So any help would be greatly welcome!
Best regards,
Thierry

Resources