0

My dictionary is below, I have loaded the cluster

[
{'id':1,  'name': 'weather report', 'description': 'Today is cooler weather'},
{'id':2,  'name': 'weather report', 'description': 'Today is hotter weather'},
{'id':3,  'name': 'weather report', 'description': 'Today is warm weather'}
]

I loaded the cluster

for i in wea:
    es.index(index="wea", body=i, id=i['id'])
  • I am searching for hot*
  • I have stop words hotter
  • so in the output there is no content

Below is the code

es.indices.close("wea")
settings = {
  "settings": {
    "analysis": {
      "analyzer": {
        "blogs_analyzer": {
          "type": "standard",
          "stopwords": [
            "hotter"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      },
      "name": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      },
      "description": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      }
    }
  }
}
# es.indices.create(index="wea", ignore=400, body=settings)
es.indices.put_settings(index="wea", body=settings)
es.indices.open("wea")
  • The above scenario is perfectly working fine. now the problem

If i am changing my stopwords from 'hotter' to 'cooler' and i am searching cool* then my output has to be empty.

but I am getting {'id':3, 'name': 'weather report', 'description': 'Today is cooler weather'}

I found one solution i have to reload the cluster? Is that correct approach? any way to achieve without reloading

sim
  • 524
  • 3
  • 14

1 Answers1

1

Instead of reloading the cluster, you can close the index and use the update index settings API to update the analyzer configuration, then reopen the index.

You can use the below commands :

POST /<index-name>/_close

PUT /<index-name>/_settings
{
    "analysis": {
        "analyzer": {
            "blogs_analyzer": {
                "type": "standard",
                "stopwords": [
                    "hotter",
                    "cooler"
                ]
            }
        }
    }
}

POST /<index-name>/_open

The updated stopwords would only apply to new or modified documents, not to existing documents.

You must reindex the documents if you want to apply the modifications to the existing documents.

ESCoder
  • 15,431
  • 2
  • 19
  • 42
  • I am glad to say you are super in ES – sim Jun 20 '22 at 05:30
  • where you find `You must reindex the documents if you want to apply the modifications to the existing documents.` – sim Jun 20 '22 at 06:27
  • @sim Thanks for your kind words ;-) whenever you update the index settings, the new index setting will not automatically apply to the already existing documents. If you want to update the documents then you have to reindex the documents. – ESCoder Jun 21 '22 at 03:16
  • https://stackoverflow.com/questions/72964121/how-to-add-suggestion-inside-term-query-in-dsl – sim Jul 13 '22 at 11:33