gpt4 book ai didi

json - 自定义分析器出现在类型映射中但在Elasticsearch中不起作用

转载 作者:行者123 更新时间:2023-12-03 00:17:56 25 4
gpt4 key购买 nike

我试图将自定义分析器添加到索引中,同时还将该分析器映射到类型上的属性。这是我执行此操作的JSON对象:

{ "settings" : {
"analysis" : {
"analyzer" : {
"test_analyzer" : {
"type" : "custom",
"tokenizer": "standard",
"filter" : ["lowercase", "asciifolding"],
"char_filter": ["html_strip"]
}
}
}
},
"mappings" : {
"test" : {
"properties" : {
"checkanalyzer" : {
"type" : "string",
"analyzer" : "test_analyzer"
}
}
}
}
}

我知道此分析器有效,因为我已经使用 /wp2/_analyze?analyzer=test_analyzer -d '<p>Testing analyzer.</p>'测试了它,并且当我检查 /wp2/test/_mapping时,它也显示为checkanalyzer属性的分析器。但是,如果添加像 {"checkanalyzer": "<p>The tags should not show up</p>"}这样的文档,则当我使用 _search端点检索文档时,HTML标记不会被剥离。我是否误解了映射的工作方式,或者我的JSON对象有问题?当我对Elasticsearch进行此调用时,我正在动态创建wp2索引以及测试类型,不确定是否很重要。

最佳答案

html不会从源中删除,而是从该源生成的术语中删除。如果使用terms aggregation,则可以看到此信息:

POST /test_index/_search
{
"aggs": {
"checkanalyzer_field_terms": {
"terms": {
"field": "checkanalyzer"
}
}
}
}

{
"took": 77,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"checkanalyzer": "<p>The tags should not show up</p>"
}
}
]
},
"aggregations": {
"checkanalyzer_field_terms": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "not",
"doc_count": 1
},
{
"key": "should",
"doc_count": 1
},
{
"key": "show",
"doc_count": 1
},
{
"key": "tags",
"doc_count": 1
},
{
"key": "the",
"doc_count": 1
},
{
"key": "up",
"doc_count": 1
}
]
}
}
}

这是我用来测试的一些代码:

http://sense.qbox.io/gist/2971767aa0f5949510fa0669dad6729bbcdf8570

关于json - 自定义分析器出现在类型映射中但在Elasticsearch中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34322588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com