elasticsearch edge_ngrams analyzer is not found - elasticsearch

I am following an official video from elasticsearch
and they said to do this:
PUT /blablabla/doc/_mapping
{
"properties": {
"title" : {
"type": "string",
"fields": {
"stemmed" : {
"type": "string",
"analyzer": "english"
},
"autocomplete" : {
"type": "string",
"analyzer": "edge_ngrams"
}
}
}
}
}
I got error that the analyzer edge_ngrams is not exists
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "analyzer [edge_ngrams] not found for field [autocomplete]"
}
],
"type": "mapper_parsing_exception",
"reason": "analyzer [edge_ngrams] not found for field [autocomplete]"
},
"status": 400
}
why please ?
I am on elasticsearch 2.2
Update
calling GET /blablabla i get the following
{
"blablabla": {
"aliases": {},
"mappings": {
"doc": {
"properties": {
"job": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"settings": {
"index": {
"creation_date": "1456267981541",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "5042-5UwR42QY45jMRw8jQ",
"version": {
"created": "2010199"
}
}
},
"warmers": {}
}
}

The correct name of analyzer is edgeNGram and not edge_ngrams. Checkout this link
The default values for min_gram and max_gram are 1 and 2 respectively. In most of the cases, you may need to provide your custom analyzer.
You may like to check how to do this at this reference

Related

adding a script-based field to an elasticSearch index mapping

I am following the following docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-indexed.html
I have a field which I would like to not be scripted on runtime but rather on index-time, and according to above I can do that simply by putting the field and its script inside the mapping object as normal.
Here is a simplified version of the index I'm trying to create
{
"settings": {
"analysis": {
"analyzer": {
"case_insensitive_analyzer": {
"type": "custom",
"filter": ["lowercase"],
"tokenizer": "keyword"
}
}
}
},
"mappings": {
"properties": {
"id": {
"type": "text"
},
"events": {
"properties": {
"fields": {
"type": "text"
},
"id": {
"type": "text"
},
"event": {
"type": "text"
},
"time": {
"type": "date"
},
"user": {
"type": "text"
},
"state": {
"type": "integer"
}
}
},
"eventLast": {
"type": "date",
"on_script_error": "fail",
"script": {
"source": "def events = doc['events']; emit(events[events.length-1].time.value"
}
}
}
}
}
I'm getting this 400 error back:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "unknown parameter [script] on mapper [eventLast] of type [date]"
}
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [_doc]: unknown parameter [script] on mapper [eventLast] of type [date]",
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "unknown parameter [script] on mapper [eventLast] of type [date]"
}
},
"status": 400
}
Essentially I'm trying to create a scripted indexed field that is calculated off the last event time in the events array of the document.
Thanks
Tldr;
As the error states, you can not define your script in here.
There is a specific way to create runtime fields in elasticsearch.
You need to put the definition at the root of the json in the runtime object.
Solution
{
"settings": {
"analysis": {
"analyzer": {
"case_insensitive_analyzer": {
"type": "custom",
"filter": ["lowercase"],
"tokenizer": "keyword"
}
}
}
},
"runtime": {
"eventLast": {
"type": "date",
"on_script_error": "fail",
"script": {
"source": "def events = doc['events']; emit(events[events.length-1].time.value"
}
}
},
"mappings": {
"properties": {
"id": {
"type": "text"
},
"events": {
"properties": {
"fields": {
"type": "text"
},
"id": {
"type": "text"
},
"event": {
"type": "text"
},
"time": {
"type": "date"
},
"user": {
"type": "text"
},
"state": {
"type": "integer"
}
}
}
}
}
}

ElasticSearch creating index returns error

I'm using elasticsearch v. 6.2.2 and try to Create an Index in Kibana 6.2.2:
I get this code from guide for beginners https://www.codementor.io/ashish1dev/getting-started-with-elasticsearch-du107nett
PUT /company
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "string",
"analyzer": "analyzer-name"
}
}
}
}
}
}
I get an error after executing this request
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.properties.age.type] 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.mappings.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
},
"status": 400
}
After I wanted to do like here
POST /company/employee/?_create
{
"name": "Andrew",
"age" : 45,
"experience" : 10
}
Could you please answer what's wrong with this code
mappings cannot be nested inside settings and must be a top-level section:
PUT /company
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "string",
"analyzer": "analyzer-name"
}
}
}
}
}

ElasticSearch :: Exception while ceating index and document

I am new to ElasticSearch & was trying to execute the example mentioned in their home page where I came across this erorr -
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.age.type] 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.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
"suppressed": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.experience.type] 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.mappings.employee.properties.name.analyzer] 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.mappings.employee.properties.name.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
]
},
"status": 400
}
The url & body of the post request are as follows -
URL - > http://localhost:9200/company
BODY - >
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "string",
"analyzer": "analyzer-name"
}
}
}
}
}
}
How to fix the error ?
There are two errors in syntax of your JSON body object:
Node settings must have only two childs: index and analysis. Node mappings must be root-level.
Field name has invalid type string, it must be text or keyword. Because you need this field to be analyzed, it should be text in your case.
So working query for ES version 6.x (that was current at the time of the question) should be like this:
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "analyzer-name"
}
}
}
}
}
Starting from ES version 7.0, mapping types was removed from index definition, so the query above wouldn't work in ES 7.x.
Working query for ES version 7.x could be two types:
If index should contain data only about employees, you can simply delete employee mapping type and query would be like this:
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "analyzer-name"
}
}
}
}
If index should contain data about employees and some other data, you can use employee as field of the object type and query would be like this:
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"properties": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "analyzer-name"
}
}
}
}
}
}
As you mentioned that you are new to Elastic Search, better start with the basic and use the default settings of ElasticSearch. Use the following mapping:
curl -XPUT localhost:9200/company -d '{
"mappings": {
"employee": {
"properties": {
"age": {"type": "long"},
"experience": {"type": "long"},
"name": {"type": "string","index": "not_analyzed"}
}
}
}
}'

Add mapping on elastic search index field

I would like to add anaylyser uax_url_email for search email field in elasticsearch document. However, I get the error.
Here is the code I am using to create this index
{
"user": {
"aliases": {},
"mappings": {
"user": {
"properties": {
"created": {
"type": "date"
},
"email": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "user",
"creation_date": "1521016015646",
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"type": "uax_url_email",
"max_token_length": "255"
}
}
},
"number_of_replicas": "1",
"uuid": "RS96V9gFQbG5UmoQ2R_gLA",
"version": {
"created": "6010099"
}
}
}
}
}
PUT /user/_mapping/email
{
"mappings": {
"_doc": {
"properties": {
"email": {
"type": "text",
"fields": {
"my_analyzer": {
"email": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
}
}
I got an error stating "root_cause":
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [mappings : {_doc={properties={email={type=text, fields={my_analyzer={email=text, analyzer=my_analyzer}}}}}}]"
}
],
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [mappings : {_doc={properties={email={type=text, fields={my_analyzer={email=text, analyzer=my_analyzer}}}}}}]"
},
"status": 400
}
Nothing will be found. I want my analyzer and tokenizer work on email field any help will be highly appreciated
This should work:
PUT /user/_mapping/user
{
"properties": {
"email": {
"type": "text",
"fields": {
"my_analyzer": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
Your mistake was that you thought that the index type was _doc, but looking at your mapping, the index type is user. Basically, you have a user index with a user type.
The format of the command is PUT /[INDEX_NAME]/_mapping/[TYPE_NAME] {"properties:" { "[FIELD_TO_BE_UPDATED]": {....} } }.

Elasticsearch mapping issue when one index already existed from before

whenever there is one index already present in Elastic search and I try to create another index with following steps.
1) create an empty index called dsi2 with settings and analyzer
curl -XPUT 'https://instance:9243/dsi2' -d '{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer_keyword": {
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
}
}'
2) create mapping,
curl -XPUT 'https://instance:9243/_mapping/dsi2' -d '{
"_all": {
"enabled": true
},
"properties": {
"formTypeId": {
"type": "integer"
},
"status": {
"type": "integer"
},
"tenantId": {
"type": "integer"
},
"formDefinitionId": {
"type": "integer"
},
"instance": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"fields": {
"raw": {
"type": "integer",
"index": "not_analyzed"
}
.....
it throws
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "analyzer [analyzer_keyword] not found for field [raw]"
}
],
"type": "mapper_parsing_exception",
"reason": "analyzer [analyzer_keyword] not found for field [raw]"
},
"status": 400
}
there is no issue in creating mapping for dsi2 when dsi2 is the only index that was created with same steps 1) & 2) above. if there is already one index created to prior to dsi2 - though both indices are separate indices - is there any conflict with the mapping?

Resources