我是 elasticsearch 的新手,正在测试 html_strip 过滤器。理想情况下,我不应该能够搜索 HTML 标签。以下是步骤。
Index:
curl -XPOST 'localhost:9200/foo/test/_analyzer?tokenizer=standard&char_filters=html_strip' -d '
{
"content" : "<title>Dilip Kumar</title>"
}'
Search:
http://localhost:9200/foo/test/_search?tokenizer=standard&char_filters=html_strip&q=title
Result:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2169777,
"hits": [
{
"_index": "foo",
"_type": "test",
"_id": "_analyzer",
"_score": 0.2169777,
"_source": {
"content": "<title>Dilip Kumar</title>"
}
}
]
}
}
UPDATE按照建议;我使用了以下映射并在删除现有索引后重复上述步骤,但我仍然能够搜索标记。
curl -XPUT "http://localhost:9200/foo " -d'
{
"foo": {
"settings": {
"analysis": {
"analyzer": {
"html_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"standard",
"lowercase",
"stop",
"asciifolding"
],
"char_filter": [
"html_strip"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"standard",
"lowercase",
"stop",
"asciifolding"
]
}
}
}
},
"mappings": {
"test": {
"properties": {
"content": {
"type": "string",
"index_analyzer": "html_analyzer",
"search_analyzer": "whitespace_analyzer"
}
}
}
}
}
}'