将 uax_url_email 分析器添加到 Elasticsearch 2.4.5

Adding uax_url_email analyzer to Elasticsearch 2.4.5

我正在尝试添加使用 uax_url_email 分词器的 分析器

▶ elasticsearch --version
Version: 2.4.5, Build: c849dd1/2017-04-24T16:18:17Z, JVM: 1.8.0_131

curl -XPUT http://localhost:9200/timeline -H 'Content-Type: application/json' -d'
{
    "settings": {
        "analysis": {
            "analyzer": {
                "email_analyzer": {
                    "type": "custom",
                    "tokenizer": "uax_url_email"
                }
            }
        }
    }
}'

但是这会抱怨索引已经存在。

{
    "error": {
        "index": "timeline",
        "reason": "already exists",
        "root_cause": [
            {
                "index": "timeline",
                "reason": "already exists",
                "type": "index_already_exists_exception"
            }
        ],
        "type": "index_already_exists_exception"
    },
    "status": 400
}

所以我尝试通过 PATCH

进行更新
curl -XPATCH http://localhost:9200/timeline -H 'Content-Type: application/json' -d'
{
    "settings": {
        "analysis": {
            "analyzer": {
                "email_analyzer": {
                    "type": "custom",
                    "tokenizer": "uax_url_email"
                }
            }
        }
    }
}'

这不会抱怨任何问题,returns 没有错误并且返回的输出与我向 /timeline 索引发出 GET 请求一样

输出中有趣的部分是设置尚未更新。

    "settings": {
        "index": {
            "creation_date": "1497609042039",
            "number_of_replicas": "1",
            "number_of_shards": "5",
            "uuid": "XaRS0KN1SLWcBsl6eLMZcg",
            "version": {
                "created": "2040599"
            }
        }
    },

我可能错误地期望新 PATCHED analysis 对象出现...

不确定我哪里出错了。

您需要先关闭索引,然后再打开:

curl -XPOST 'localhost:9200/timeline/_close'

curl -XPUT 'localhost:9200/timeline/_settings' -d '{
  "analysis" : {
    "analyzer":{
      "email_analyzer":{
        "type":"custom",
        "tokenizer":"uax_url_email"
      }
    }
  }
}'

curl -XPOST 'localhost:9200/timeline/_open'