将分析器添加到字段中

时间:2016-10-03 09:15:33

标签: elasticsearch

我有一个名为placess的类型,如下所示:

 "name" : {
        "type" : "string"
      },

我创建了一个分析器如下:

curl -XPUT 'localhost:9200/ashojash/_settings' -d '{
"settings": {
    "analysis": {
        "filter": {
            "autocomplete_filter": { 
                "type":     "edge_ngram",
                "min_gram": 1,
                "max_gram": 20
            }
        },
        "analyzer": {
            "autocomplete": {
                "type":      "custom",
                "tokenizer": "standard",
                "filter": [
                    "lowercase",
                    "autocomplete_filter" 
                ]
            }
        }
    }
}

} “ 我的问题是如何将此分析器添加到名为name的现有字段中?

我试过

curl -XPUT 'http://localhost:9200/ashojash/_mapping/venues' -d '
{
"venues" : {
    "properties" : {
        "name" : {
            type:"string",
            "analyzer": "persian"
            }
    }
 }
}'

但是这给了我冲突字段[name]已经存在 如何将此分析器添加到名为name的现有字段中?

1 个答案:

答案 0 :(得分:0)

您需要在创建索引的同时执行此操作(在创建后无法将分析器更改为字段):

curl -XPUT 'localhost:9200/ashojash' -d '{
  "settings": {
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 20
        }
      },
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "autocomplete_filter"
          ]
        }
      }
    }
  },
  "mappings": {
    "venues": {
      "properties": {
        "name": {
          "type": "string",
          "analyzer": "autocomplete"
        }
      }
    }
  }
}'