es自定义分词器支持数字字母分词,中文分词器jieba支持添加禁用词和扩展词典

自定义分析器,分词器

json 复制代码
PUT http://xxx.xxx.xxx.xxx:9200/test_index/
{
  "settings": {
    "analysis": {
      "analyzer": {
        "char_test_analyzer": {
          "tokenizer": "char_test_tokenizer",
          "filter": [
            "lowercase"
          ]
        }
      },
      "tokenizer": {
        "char_test_tokenizer": {
          "type": "ngram",
          "min_gram": 1,
          "max_gram": 2
        }
      }
    }
  },
  "mappings": {
    "test_zysf_index": {
      "properties": {
        "text": {
          "type": "text",
          "analyzer": "char_test_analyzer"
        }
      }
    }
  }
}

所有字段检索

json 复制代码
{
	"query": {
		"multi_match": {
			"query": "河北保定",
			"type": "cross_fields",
			"fields": ["*"],
			"operator": "AND"
    }
	}
}

高亮搜索

json 复制代码
{
  "highlight": {
    "fields": {
        "name": {},
        "content": {},
    },
    "pre_tags": ["<em>"],
    "post_tags": ["</em>"]
  }
}

分词测试

GET /test_index/_analyze

json 复制代码
{
  "analyzer": "char_test_analyzer",
  "text": "adfsjdsa12345646abADS"
}

jieba中文分词支持添加禁用词和扩展词库功能

创建索引:PUT http://xxxx:9200/test_index

json 复制代码
{
	"settings": {
		"analysis": {
			"filter": {
				"jieba_stopword": {
					"type": "stop",
					"stopwords_path": "/home/stopwords.txt"
				}
			},
			"tokenizer": {
	        	"jieba_tokenizer": {
		          	"type": "jieba_index",
		          	"user_dict": "/home/user.dict"
        		}
      		},
			"analyzer": {
				"my_jieba": {
					"filter": [
						"lowercase",
						"jieba_stopword"
					],
					"tokenizer": "jieba_tokenizer"
				}
			}
		}
	},
	"mappings": {
    	"test_index": {
      		"properties": {
        		"name": {
          			"type": "text",
					"index": true,
					"analyzer": "my_jieba",
					"similarity": "BM25"
        		}
      		}
    	}
  	}
}

分词测试:

GET http://xxxxxx:9200/test_index/_analyze

json 复制代码
{
  "analyzer": "my_jieba",
  "text": "中国你好,我爱你中国"
}
相关推荐
Leo.yuan27 分钟前
数据分析师如何构建自己的底层逻辑?
大数据·数据仓库·人工智能·数据挖掘·数据分析
Aurora_NeAr1 小时前
Apache Iceberg数据湖高级特性及性能调优
大数据·后端
SoFlu软件机器人1 小时前
飞算科技正在撬动各行业数字化转型的深层变革
大数据·科技
samLi06204 小时前
【工具变量】全国省市区县土地出让结果公告数据(2000-2024年)
大数据
chevysky.cn6 小时前
Elasticsearch部署和集成
大数据·elasticsearch·jenkins
SelectDB技术团队7 小时前
森马服饰从 Elasticsearch 到阿里云 SelectDB 的架构演进之路
elasticsearch·阿里云·doris
青云交7 小时前
Java 大视界 -- Java 大数据在智能医疗远程手术机器人操作数据记录与分析中的应用(342)
java·大数据·数据记录·远程手术机器人·基层医疗·跨院协作·弱网络适配
Elasticsearch8 小时前
Elastic 被评为 2025 年 Gartner® 可观测平台魔力象限™中的领导者
elasticsearch
武子康8 小时前
大数据-38 Redis 分布式缓存 详细介绍 缓存、读写、旁路、穿透模式
大数据·redis·后端