栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Elasticsearch:使用文档中的自定义分数字段进行影响力评分

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Elasticsearch:使用文档中的自定义分数字段进行影响力评分

解决此问题的另一种方法是使用嵌套文档:

首先设置映射以创建

vocab
一个嵌套文档,这意味着每个
wtag
/
rscore
文档将在内部作为单独的文档建立索引:

curl -XPUT "http://localhost:9200/myindex/" -d'{  "settings": {"number_of_shards": 1},   "mappings": {    "mytype": {      "properties": {        "vocab": {          "type": "nested",          "fields": { "wtag": {   "type": "string" }, "rscore": {   "type": "float" }          }        }      }    }  }}'

然后索引您的文档:

curl -XPUT "http://localhost:9200/myindex/mytype/1" -d'{  "vocab": [    {      "wtag": "James Bond",      "rscore": 2.14    },    {      "wtag": "world",      "rscore": 0.86    },    {      "wtag": "somemore",      "rscore": 3.15    }  ]}'curl -XPUT "http://localhost:9200/myindex/mytype/2" -d'{  "vocab": [    {      "wtag": "hiii",      "rscore": 1.34    },    {      "wtag": "world",      "rscore": 0.94    },    {      "wtag": "somemore",      "rscore": 3.23    }  ]}'

并运行

nested
查询以匹配所有嵌套文档,并
rscore
为每个与之匹配的嵌套文档求和:

curl -XGET "http://localhost:9200/myindex/mytype/_search" -d'{  "query": {    "nested": {      "path": "vocab",      "score_mode": "sum",      "query": {        "function_score": {          "query": { "match": {   "vocab.wtag": "james bond world" }          },          "script_score": { "script": "doc["rscore"].value"          }        }      }    }  }}'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401386.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号