How can I define Settings and Analyzer for ElasticSearch?

懵懂的女人 提交于 2019-12-11 10:41:19

问题


I am using Grails with the ElasticSearch Plugin. It works fine, but I need to define the settings and analyzer.

How can I do that?

I want to use the following settings and mappings:

{
 "settings" : {
   "index" : {
    "analysis" : {
      "analyzer" : {
         "autocomplete" : "engram", 
         "filter" : ["lowercase"]
       }
     },
     "tokenizer" : {
        "engram" : {
          "type" : "edgeNgram", 
          "min_gram" : 3,
          "max_gram" : 10
      }
     }
    }
   }
  },
  "mappings" : {
    "contacts" : {
      "name" : {
        "index" : "string",
        "index_analyzer" : "autocomplete",
        "index" : "analyzed", "search_analyzer" : "standard"
      },
      "country" : { "type" : "string" }
    }
   }
  }
}

回答1:


As dmahaptro suggests, using Elasticsearch's Rest API would work. From http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/ under the "mappings" header, you can copy and paste the following into your shell:

curl -XPOST localhost:9200/index_name -d '{
"settings" : {
   "index" : {
    "analysis" : {
      "analyzer" : {
         "autocomplete" : "engram", 
         "filter" : ["lowercase"]
       }
     },
     "tokenizer" : {
        "engram" : {
          "type" : "edgeNgram", 
          "min_gram" : 3,
          "max_gram" : 10
      }
     }
    }
   }
  },
  "mappings" : {
    "contacts" : {
      "name" : {
        "index" : "string",
        "index_analyzer" : "autocomplete",
        "index" : "analyzed", "search_analyzer" : "standard"
      },
      "country" : { "type" : "string" }
    }
   }
  }
}'

A way to check that your index was created with the correct settings is to use the head plugin: https://github.com/mobz/elasticsearch-head. Fire up the head plugin in your browser and click the "Cluster State" tab for all of your indexes and their settings, mappings, etc.



来源:https://stackoverflow.com/questions/18188370/how-can-i-define-settings-and-analyzer-for-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!