Elasticsearch 设置分析器示例

为一个字段指定分析器

在创建索引时指定

PUT my_index
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "whitespace"
      }
    }
  }
}

为索引指定一个默认的分析器

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "default": {
          "type": "simple"
        }
      }
    }
  }
}

指定匹配项分析器

GET my_index/_search
{
  "query": {
    "match": {
      "message": {
        "query": "Quick foxes",
        "analyzer": "stop"
      }
    }
  }
}

指定字段搜索分析器

可以在创建索引映射时使用search_analyzer 参数为每个text字段指定搜索分析器。
如果提供了搜索分析器,则还必须使用analyzer参数指定索引分析器。

PUT my_index
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "whitespace",
        "search_analyzer": "simple"
      }
    }
  }
}

指定默认的搜索分析器

当创建索引,可以使用设置默认搜索仪analysis.analyzer.default_search设置。如果提供了搜索分析器,则还必须使用该analysis.analyzer.default设置指定默认的索引分析器。

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "default": {
          "type": "simple"
        },
        "default_search": {
          "type": "whitespace"
        }
      }
    }
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章