爲一個字段指定分析器
在創建索引時指定
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"
}
}
}
}
}