【问题标题】:How can I define Settings and Analyzer for ElasticSearch?如何为 ElasticSearch 定义设置和分析器?
【发布时间】:2013-08-12 13:33:40
【问题描述】:

我正在使用带有ElasticSearch Plugin 的Grails。它工作正常,但我需要定义设置和分析器。

我该怎么做?

我想使用以下设置和映射:

{
 "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" }
    }
   }
  }
}

【问题讨论】:

  • 在这里查看the docs。请注意,您将无法在 analyzers 中使用 nGram 过滤器。在这种情况下,您必须按原样使用依赖项而不是插件。
  • @dmahapatro 我已经更新了我的问题。你可以看到我想要实现的东西。知道该怎么做吗?
  • 我担心你不能使用插件来做到这一点,这就是为什么我在你之前的问题中指出直接使用弹性搜索而不使用插件。另一方面,如果您只想在本地弹性服务器中创建映射,则继续为上述 json 使用 REST PUT,这应该会创建分析器。 (使用卷曲)

标签: spring grails elasticsearch grails-2.0


【解决方案1】:

正如 dmahaptro 所建议的那样,使用 Elasticsearch 的 Rest API 是可行的。从“mappings”标题下的http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/,您可以将以下内容复制并粘贴到您的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" }
    }
   }
  }
}'

检查索引是否使用正确设置创建的一种方法是使用头插件:https://github.com/mobz/elasticsearch-head。在浏览器中启动 head 插件,然后单击所有索引及其设置、映射等的“集群状态”选项卡。

【讨论】:

    猜你喜欢
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 2014-08-08
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多