当咱们建设一个 index 的时候,能够为 index 创立专属的 analyzer

这个 analyzer 的只是该 index 可见,而不是全局的

PUT /my_index{  "mappings": {    "properties": {      "title": {         "type": "text",        "analyzer": "my_analyzer"      },      "content": {        "type": "text"      }    }  },  "settings": {    "analysis": {      "analyzer": {        "my_analyzer": {           "type": "custom",          "tokenizer": "standard",          "filter": [            "lowercase",            "my_synonyms"          ]        }      },      "filter": {        "my_synonyms": {           "type": "synonym",          "synonyms_path": "analysis/synonyms.txt"        }      }    }  }}

有这么一个需要,咱们心愿,应用 python sdk 查看 analyzer 的后果,怎么办?

很简略:

es.indices.analyze(    index=index_name,    body={        "analyzer": "sentence_analyzer",        "text": content,    })

加上 index=index_name 参数就好了,不然会遇到报错: failed to find global analyzer [sentence_analyzer]