Elasticsearch index analyzer settings - elasticsearch

I am a beginner for elastic search. I tried to add an analyzer to my index. Here is the coding:
PUT drug_mono6/_settings
{
"analysis": {
"analyzer": {
"attachment.content": {
"type": "custom",
"tokenizer": "Whitespace"
}
}
}
}
However, I was not able to reopen the index after doing that. The error I received is:
{
"error": {
"root_cause": [
{
"type": "exception",
"reason": "Failed to verify index [drug_mono6/SMmaJ4iPTCSUHp-oedsadA]"
}
],
"type": "exception",
"reason": "Failed to verify index [drug_mono6/SMmaJ4iPTCSUHp-oedsadA]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "analyzer [attachment] must specify either an analyzer type, or
a tokenizer"
}
},
"status": 500
}`
Is there a way to modify the settings and remove the changes?

this should work
PUT drug_mono6
{
"analysis": {
"analyzer": {
"attachment": {
"type": "custom",
"tokenizer": "whitespace"
}
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html

Related

How to make a field to have lowercase analyzer after field creation?

I run
PUT /vehicles/_doc/123
{
"make" : "Honda civic",
"color" : "Blue",
"from": "Japan",
"size": "Big",
"HP" : 250,
"milage" : 24000,
"price": 19300.97
}
at the start
and after that I run
PUT /vehicles
{
"settings": {
"analysis": {
"analyzer": {
"my_lowercase_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"make": {
"type": "text",
"analyzer": "my_lowercase_analyzer"
}
}
}
}
It gives exception
{
"error": {
"root_cause": [
{
"type": "resource_already_exists_exception",
"reason": "index [vehicles/o66DtxmERa2lmo2WiiZ65w] already exists",
"index_uuid": "o66DtxmERa2lmo2WiiZ65w",
"index": "vehicles"
}
],
"type": "resource_already_exists_exception",
"reason": "index [vehicles/o66DtxmERa2lmo2WiiZ65w] already exists",
"index_uuid": "o66DtxmERa2lmo2WiiZ65w",
"index": "vehicles"
},
"status": 400
}
Is there away to update analyzer after creation?
Updating the analyzer of an existing field is a breaking change, you can't update it on the same index, you now have below. options
Add another field, on which you can define the new analyzer (of-course this is not recommended as you will loose the old data, but in some cases it may be useful).
Create a new index using same field and updated analyzer definition and after that you can use reindex API to update the data from old to new index.

Getting "resource_already_exists_exception" when trying to update stopwords

I'm using Elasticsearch version 6.8
I have an exsisting index (name q1) and I want to update it's stop words list.
I tried to do it with the following command:
PUT /q1
{
"settings": {
"analysis": {
"filter": {
"my_stop": {
"type": "stop",
"stopwords": ["daa", "dada", "the"]
}
}
}
}
}
But I got errors:
{
"error": {
"root_cause": [
{
"type": "resource_already_exists_exception",
"reason": "index [q1/lywbfw9QTaeYVr0dpDnRvw] already exists",
"index_uuid": "lywbfw9QTaeYVr0dpDnRvw",
"index": "q1"
}
],
"type": "resource_already_exists_exception",
"reason": "index [q1/lywbfw9QTaeYVr0dpDnRvw] already exists",
"index_uuid": "lywbfw9QTaeYVr0dpDnRvw",
"index": "q1"
},
"status": 400
}
seems that I can set the stop words (with this command) just for a new index and not for exsisting one.
What is wrong, and how can I update the stop words list of my q1 index ?
Thanks
you need to close your index for updating and open it after.
See more about closing https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-close.html
and opening index https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html
https://hostname:9200/your_index_name/_close
after
PUT /your_index_name/_settings
{
"settings": {
"analysis": {
"filter": {
"my_stop": {
"type": "stop",
"stopwords": ["daa", "dada", "the"]
}
}
}
}
}
then
https://hostname:9200/your_index_name/_open

IOException while reading synonyms_path_path (synonyms token filter)

I am using synonyms token filter with custom file
installed elasticsearch 6.7 as a service on windows 10 machine
my synonyms.txt is located at C:\ProgramData\Elastic\Elasticsearch\config\analysis\synonyms.txt
here is my index settings
PUT /synonyms
{
"settings": {
"analysis": {
"filter": {
"synonym": {
"type": "synonym",
"synonyms_path": "analysis/synonyms.txt"
}
},
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym"
]
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"description": {
"type": "text",
"analyzer": "my_analyzer"
}
}
}
}
}
I am getting this error while creating above index
{
"error": {
"root_cause": [{
"type": "illegal_argument_exception",
"reason": "IOException while reading synonyms_path_path: C:\ProgramData\Elastic\Elasticsearch\config\analysis\synonyms.txt"
}],
"type": "illegal_argument_exception",
"reason": "IOException while reading synonyms_path_path: C:\ProgramData\Elastic\Elasticsearch\config\analysis\synonyms.txt",
"caused_by": {
"type": "no_such_file_exception",
"reason": "C:\ProgramData\Elastic\Elasticsearch\config\analysis\synonyms.txt"
}
},
"status": 400
}
also tried synonyms token filter in elasticsearch installed as archive distribution .zip on windows machine but getting same error
but in linux machine for both archive as well as package distributions it is working.
Thanks in advance. Happy searching
the problem here is the file extensions are hidden from control panel.so you can just go to control panel>file explorer options> click on view tab there uncheck option(hide extension for known file types)
it should look something like this
now rename your file accordingly and try again

Invalid synonym rule when using two files

I have two synonyms files with few thousand lines, here is the sample causing the problem:
en_synonyms file :
cereal, semolina, wheat
fr_synonyms file :
ble, cereale, wheat
This is the error I got :
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "failed to build synonyms"
}
],
"type": "illegal_argument_exception",
"reason": "failed to build synonyms",
"caused_by": {
"type": "parse_exception",
"reason": "Invalid synonym rule at line 1",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "term: wheat analyzed to a token (cereal) with position increment != 1 (got: 0)"
}
}
},
"status": 400
}
The mapping I used:
PUT wheat_syn
{
"mappings": {
"wheat": {
"properties": {
"description": {
"type": "text",
"fields": {
"synonyms": {
"type": "text",
"analyzer": "syn_text"
},
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"en_synonyms": {
"type": "synonym",
"tokenizer": "keyword",
"synonyms_path" : "analysis/en_synonyms.txt"
},
"fr_synonyms": {
"type": "synonym",
"tokenizer": "keyword",
"synonyms_path" : "analysis/fr_synonyms.txt"
}
},
"analyzer": {
"syn_text": {
"tokenizer": "standard",
"filter": ["lowercase", "en_synonyms", "fr_synonyms" ]
}
}
}
}
}
Both files contain the term wheat when I remove it from one of them, the index is created successfully.
I thought about combining the two files, so the result will be :
cereal, semolina, wheat, ble, cereale
But in my case I can't do that manually since it will take a lot of time (I'll look for a way to do it programmatically, depending on the answer to this question)
Found a simple soltion:
Instead of using two files, I just concatenated the content of en_synonyms and fr_synonyms in one file all_synonyms:
cereal, semolina, wheat
ble, cereale, wheat
Then used it for the mapping.

Set values in multifields elastic search

I have the following structure recorded in elastic:
PUT /movies
{
"mappings": {
"title": {
"properties": {
"title": {
"type": "string",
"fields": {
"de": {
"type": "string",
"analyzer": "german"
},
"en": {
"type": "string",
"analyzer": "english"
},
"fr": {
"type": "string",
"analyzer": "french"
},
"es": {
"type": "string",
"analyzer": "spanish"
}
}
}
}
}
}
}
But when I am trying to record values like this:
PUT movies/_doc/2
{
"title": "fox",
"field": "en"
}
I receive the following error:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [movies] as the final mapping would have more than 1 type: [_doc, title]"
}
],
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [movies] as the final mapping would have more than 1 type: [_doc, title]"
},
"status": 400
}
Maybe I am doing something wrong since I am fairly new to elastic. My idea is to create one to one mapping and when I am searching for Fox in any of these languages to return results only in english since they are recorded in the DB.
Your mapping indicates a mapping type "title" but when you create the documents you use PUT movies/_doc/2 that indicates mapping type _doc which doesn't exist so ES will try to automatically create it, and in newer version of ES having multiple mapping types is forbidden.
You should just change it to: PUT movies/title/2

Resources