为一个字段指定分析器
在创建索引时指定
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"
}
}
}
}
}