elasticsearch - 在弹性搜索中按权重过滤拼写建议结果
问题描述
首先,我使用以下映射索引了一些文档:
{
"test_index": {
"mappings": {
"dynamic": "strict",
"properties": {
"content_completion": {
"type": "completion",
"analyzer": "hashtag_analyzer",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"fields": {
"content": {
"type": "text",
"analyzer": "shingle_analyzer"
}
}
}
}
}
}
}
然后我使用以下方法在其中放入了一些文档:
PUT test/_doc/1?refresh
{
"content_completion" : {
"input": "nobel",
"weight" : 5
},
"content_completion" : {
"input": "nobel marathon",
"weight" : 5
},
"content_completion" : {
"input": "nobel is good",
"weight" : 5
},
"content_completion" : {
"input": "nobel is life",
"weight" : 5
},
"content_completion" : {
"input": "no bei",
"weight" : 1000000000
}
}
(索引中没有重复的文档。)我有以下拼写建议查询:
{
"suggest": {
"text": "nobei",
"spell-checker-suggest": {
"phrase": {
"field": "content_completion.content",
"gram_size": 2,
"size": 10,
"analyzer": "hashtag_analyzer",
"real_word_error_likelihood": 0.95,
"direct_generator": [
{
"field": "content_completion.content",
"min_doc_freq": "1",
"suggest_mode": "missing",
"prefix_length": 0,
"sort": "score",
"min_word_length": 2
}
],
"highlight": {
"pre_tag": "<em>",
"post_tag": "</em>"
}
}
}
}
}
并得到这样的结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"suggest": {
"spell-checker-suggest_1": [
{
"text": "nobei",
"offset": 0,
"length": 5,
"options": [
{
"text": "nobel",
"highlighted": "<em>nobel</em>",
"score": 0.45925426
}
]
}
]
}
}
elsaticsearch 不使用权重进行评分,而只是应用频率。如果可能的话,我想要做以下其中一项:
- 使 elsaticsearch
weight
用于评分而不是frequency
- 在json 对象
weight
内显示该术语出现在它们上的 s 的总和。options
- 修改
score
使其使用weight
和计算frequency
解决方案
推荐阅读
- python - 如何根据相似字段对元组列表进行分组,然后根据另一个字段保持最大值?(不使用熊猫)
- ios - 如何在 Swift 中为 UIRefreshControl 添加可访问性
- python - 为什么我的 SQL 查询参数没有返回正确的值?
- groovy - 基于shell脚本的groovy分配映射
- asp.net-mvc - 使用 EPPlus Excel - 如何忽略 excel 错误检查或删除单元格左上角的绿色标记。(c#)
- javascript - 有没有办法在 Spring 应用程序的 JSP 页面中将 Arraylist 从 Controller 类传递到 Javascript?
- azure - U-SQL Azure Data Lake Analytics 按日期搜索文件
- phpstorm - 如何从 PhpStorm 中的项目中排除单个文件,使其不显示在搜索中?
- mysql - MySQL - 1075 表定义不正确,只能有一个自动列,必须定义为键
- python - 优化一个我不会使用的主键