elasticsearch Mappring使用自定义分词器

创建索引及配置分析器 

PUT /my_index
{
    "settings": {
        "analysis": {
            "char_filter": {
                "&_to_and": {
                    "type":       "mapping",
                    "mappings": [ "& => and "]
            }},
            "filter": {
                "my_stopwords": {
                    "type":       "stop",
                    "stopwords": [ "the", "a" ]
            }},
            "analyzer": {
                "my_analyzer": {
                    "type":         "custom",
                    "char_filter":  [ "html_strip", "&_to_and" ],
                    "tokenizer":    "standard",
                    "filter":       [ "lowercase", "my_stopwords" ]
            }}
        } 
    }
}

创建索引类型与Mapping

PUT /my_index/_mapping/_doc
{
	"_doc": {
		"properties": {
			"title": {
				"type": "text",
				"analyzer": "my_analyzer",
				"search_analyzer": "my_analyzer",
				"search_quote_analyzer": "my_analyzer"
			}
		}
	}
	
}

插入数据

POST /my_index/_doc/1

{
"title":"the a <a>你好</a> & "
}

检索

POST /my_index/_search

{
	"query": {
	    "match": {
	      "title": "你好"
	    }
	}
}

POST /my_index/_search

{
	"query": {
	    "match": {
	      "title": "and"
	    }
	}
}

POST /my_index/_search

{
	"query": {
	    "match": {
	      "title": "the a"
	    }
	}
}

猜你喜欢

转载自blog.csdn.net/ctwy291314/article/details/81391514