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"
        }
      }
    }
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章