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

elasticsearch-标记强度(嵌套/子文档增强)

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

elasticsearch-标记强度(嵌套/子文档增强)

可以通过将标签作为嵌套文档建立索引,然后将嵌套查询与自定义分数查询结合使用来完成。在下面的示例中,字词查询找到匹配的标签,自定义分数查询使用“标签”文档的“重量”字段的值作为分数,而嵌套查询使用这些分数的总和作为顶级文档的最终分数。

curl -XDELETE 'http://localhost:9200/test-idx'echocurl -XPUT 'http://localhost:9200/test-idx' -d '{    "mappings": {        "doc": { "properties": {     "title": { "type": "string" },     "tags": {         "type": "nested",         "properties": {  "tag": { "type": "string", "index": "not_analyzed" },  "weight": { "type": "float" }         }     } }        }    }}'echocurl -XPUT 'http://localhost:9200/test-idx/doc/1' -d '{    "title": "1",    "tags": [{        "tag": "A",        "weight": 1    }, {        "tag": "B",        "weight": 2    }, {        "tag": "C",        "weight": 4    }]}'echocurl -XPUT 'http://localhost:9200/test-idx/doc/2' -d '{    "title": "2",    "tags": [{        "tag": "B",        "weight": 2    }, {        "tag": "C",        "weight": 3    }]}'echocurl -XPUT 'http://localhost:9200/test-idx/doc/3' -d '{    "title": "3",    "tags": [{        "tag": "B",        "weight": 2    }, {        "tag": "D",        "weight": 4    }]}'echocurl -XPOST 'http://localhost:9200/test-idx/_refresh'echo# Example with custom script (slower but more flexable)curl -XGET 'http://localhost:9200/test-idx/doc/_search?pretty=true' -d '{    "query" : {         "nested": { "path": "tags", "score_mode": "total", "query": {     "custom_score": {         "query": {  "terms": {      "tag": ["A", "B", "D"],      "minimum_match" : 1  }         },         "script" : "doc['''weight'''].value"     } }        }    },    "fields": []}'echo


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

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

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