gpt4 book ai didi

elasticsearch - 短语提示与ngrams

转载 作者:行者123 更新时间:2023-12-02 23:44:08 25 4
gpt4 key购买 nike

因为我在搜索建议的“shingle_filter”过滤器中使用了选项“output_unigrams_if_no_shingles”:true”,因此在建议中仅显示带状疱疹,但是建议显示了ngram

        "shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3,
"output_unigrams_if_no_shingles": true
按照下面我的 map
    {
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "0",


"analysis": {
"filter": {
"stemmer_plural_portugues": {
"name": "minimal_portuguese",
"stopwords" : ["http", "https", "ftp", "www"],
"type": "stemmer"
},



"ngram_filter": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3,
"token_chars": [
"letter",
"digit"
]

},
"synonym_filter": {
"type": "synonym",
"lenient": true,
"synonyms_path": "analysis/synonym.txt",
"updateable" : false

},


"shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3,
"output_unigrams_if_no_shingles": true
}

},

"analyzer": {
"analyzer_customizado": {
"filter": [
"lowercase",
"stemmer_plural_portugues",
"asciifolding",
"synonym_filter",
"ngram_filter",
"shingle_filter"

],
"tokenizer": "lowercase"
}
}

}
}
},
"mappings": {
"properties": {

"id": {
"type": "long"
},
"data": {
"type": "date"
},
"quebrado": {
"type": "byte"

},
"pgrk": {
"type": "integer"
},
"url_length": {
"type": "integer"
},
"title": {
"analyzer": "analyzer_customizado",
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"description": {
"analyzer": "analyzer_customizado",
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"url": {
"analyzer": "analyzer_customizado",
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}

}
我在下面插入文档
{
"title": "shopping",
"description": "sex video",
"url": "www.ohcs.com"
}
在下面的建议查询中,我以错误的方式“vidio”输入“video”
    {
"suggest": {
"text": "vidio",
"simple_phrase": {
"phrase": {
"field": "description",
"size": 1,
"max_errors": 100,
"direct_generator": [
{
"field" : "description",
"suggest_mode" : "always",
"min_word_length" : 1
}
],
"collate": {
"query": {
"source" : {
"match": {
"{{field_name}}": {
"query": "{{suggestion}}",
"operator": "and"
}
}
}
},
"params": {"field_name" : "description"},
"prune": true
},
"highlight": {
"pre_tag": "<strong>",
"post_tag": "</strong>"
}
}
}
}
}
在建议搜索下方的结果中,结果显示正确的建议“视频”,但显示和多个ngram标记而不是整个单词
    {
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": [

]
},
"suggest": {
"simple_phrase": [
{
"text": "vidio",
"offset": 0,
"length": 5,
"options": [
{
"text": "vid ide deo",
"highlighted": "vid <strong>ide deo</strong>",
"score": 0.2648209,
"collate_match": true
}
]
}
]
}
}
如何获得建议的结果,以显示整个“视频”一词而不被分成几个ngram标记?

最佳答案

我按照您订购的顺序放置了映射

{
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "0",
"max_ngram_diff": 2,


"analysis": {
"filter": {
"stemmer_plural_portugues": {
"name": "minimal_portuguese",
"stopwords" : ["http", "https", "ftp", "www"],
"type": "stemmer"
},



"ngram_filter": {
"type": "ngram",
"min_gram": 1,
"max_gram": 3,
"token_chars": [
"letter",
"digit"
]

},
"synonym_filter": {
"type": "synonym",
"lenient": true,
"synonyms_path": "analysis/synonym.txt",
"updateable" : false

},


"shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3,
"output_unigrams" : false,
"output_unigrams_if_no_shingles" : true

}

},

"analyzer": {
"analyzer_customizado": {
"filter": [
"lowercase",
"stemmer_plural_portugues",
"asciifolding",
"synonym_filter",
"ngram_filter",
"shingle_filter"

],
"tokenizer": "lowercase"
}
}

}
}
},
"mappings": {
"properties": {

"id": {
"type": "long"
},
"data": {
"type": "date"
},
"quebrado": {
"type": "byte"

},
"pgrk": {
"type": "integer"
},
"url_length": {
"type": "integer"
},
"title": {
"analyzer": "analyzer_customizado",
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"description": {
"analyzer": "analyzer_customizado",
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"url": {
"analyzer": "analyzer_customizado",
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}

}
,然后我执行了下面的查询和建议
 {
"suggest": {
"text": "vidio",
"simple_phrase": {
"phrase": {
"field": "description",
"size": 1,
"max_errors": 100,
"direct_generator": [
{
"field" : "description",
"suggest_mode" : "always",
"min_word_length" : 1
}
],
"collate": {
"query": {
"source" : {
"match": {
"{{field_name}}": {
"query": "{{suggestion}}",
"operator": "and"
}
}
}
},
"params": {"field_name" : "description"},
"prune": true
},
"highlight": {
"pre_tag": "<strong>",
"post_tag": "</strong>"
}
}
}
}
}
,建议查询在下面显示错误消息
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 4,
"skipped": 0,
"failed": 1,
"failures": [
{
"shard": 4,
"index": "teste",
"node": "IW_SN_-fSkSIySZ4CO9rGA",
"reason": {
"type": "illegal_state_exception",
"reason": "At least one unigram is required but all tokens were ngrams"
}
}
]
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": [

]
}
}

关于elasticsearch - 短语提示与ngrams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62616417/

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