Elasticsearch - IndicesClient.put_settings not working

后端 未结 1 1108
春和景丽
春和景丽 2021-01-29 04:00

I am trying to update my original index settings. My initial setting looks like this:

client.create(index = \"movies\", body= {
        \"settings\": {
                  


        
1条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 05:05

    You should re-index all your data in order to apply the updated settings on all your data and fields.

    The data that had already been indexed won't be affected by the updated analyzer, only documents that has been indexed after you updated the settings will be affected.

    Not re-indexing your data might produce incorrect results since your old data is analyzed with the old custom analyzer and not with the new one.

    The most efficient way to resolve this issue is to create a new index, and move your data from the old one to the new one with the updated settings.

    Reindex Api

    Follow these steps:

    POST _reindex
    {
      "source": {
        "index": "movies"
      },
      "dest": {
        "index": "new_movies"
      }
    }
    
    DELETE movies
    
    PUT movies
    {
      "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0,
        "analysis": {
          "analyzer": {
            "my_custom_analyzer": {
              "filter": [
                "lowercase",
                "my_custom_stops",
                "my_custom_synonyms"
              ],
              "type": "custom",
              "tokenizer": "standard"
            }
          },
          "filter": {
            "my_custom_stops": {
              "type": "stop",
              "stopwords": "stop_words"
            },
            "my_custom_synonyms": {
              "ignore_case": "true",
              "type": "synonym",
              "synonyms": [
                "Harry Potter, HP => HP",
                "Terminator, TM => TM"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": {
          "body": {
            "type": "text",
            "analyzer": "my_custom_analyzer",
            "search_analyzer": "my_custom_analyzer",
            "search_quote_analyzer": "my_custom_analyzer"
          }
        }
      }
    }
    
    POST _reindex?wait_for_completion=false  
    {
      "source": {
        "index": "new_movies"
      },
      "dest": {
        "index": "movies"
      }
    }
    

    After you've verified all your data is in place you can delete new_movies index. DELETE new_movies

    Hope these help

    0 讨论(0)
提交回复
热议问题