将uax_url_email分析器添加到Elasticsearch 2.4.5

时间:2017-06-16 12:47:50

标签: elasticsearch elasticsearch-2.0

我尝试添加使用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"
                }
            }
        }
    }
}'

这并不会抱怨任何问题,不会返回任何错误,并且返回的输出与我向GET索引发出/timeline请求的情况相同

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

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

我可能错误地认为新的PATCHED 分析对象存在......

不知道我在哪里出错了。

1 个答案:

答案 0 :(得分:1)

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

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'