排序特征字段类型
编辑排序特征字段类型
编辑rank_features
字段可以索引数值特征向量,以便稍后在查询中使用 rank_feature
查询来提升文档的相关性。
它类似于 rank_feature
数据类型,但当特征列表稀疏时更适合使用,这样为每个特征在映射中添加一个字段是不合理的。
resp = client.indices.create( index="my-index-000001", mappings={ "properties": { "topics": { "type": "rank_features" }, "negative_reviews": { "type": "rank_features", "positive_score_impact": False } } }, ) print(resp) resp1 = client.index( index="my-index-000001", id="1", document={ "topics": { "politics": 20, "economics": 50.8 }, "negative_reviews": { "1star": 10, "2star": 100 } }, ) print(resp1) resp2 = client.index( index="my-index-000001", id="2", document={ "topics": { "politics": 5.2, "sports": 80.1 }, "negative_reviews": { "1star": 1, "2star": 10 } }, ) print(resp2) resp3 = client.search( index="my-index-000001", query={ "rank_feature": { "field": "topics.politics" } }, ) print(resp3) resp4 = client.search( index="my-index-000001", query={ "rank_feature": { "field": "negative_reviews.1star" } }, ) print(resp4) resp5 = client.search( index="my-index-000001", query={ "term": { "topics": "economics" } }, ) print(resp5)
const response = await client.indices.create({ index: "my-index-000001", mappings: { properties: { topics: { type: "rank_features", }, negative_reviews: { type: "rank_features", positive_score_impact: false, }, }, }, }); console.log(response); const response1 = await client.index({ index: "my-index-000001", id: 1, document: { topics: { politics: 20, economics: 50.8, }, negative_reviews: { "1star": 10, "2star": 100, }, }, }); console.log(response1); const response2 = await client.index({ index: "my-index-000001", id: 2, document: { topics: { politics: 5.2, sports: 80.1, }, negative_reviews: { "1star": 1, "2star": 10, }, }, }); console.log(response2); const response3 = await client.search({ index: "my-index-000001", query: { rank_feature: { field: "topics.politics", }, }, }); console.log(response3); const response4 = await client.search({ index: "my-index-000001", query: { rank_feature: { field: "negative_reviews.1star", }, }, }); console.log(response4); const response5 = await client.search({ index: "my-index-000001", query: { term: { topics: "economics", }, }, }); console.log(response5);
PUT my-index-000001 { "mappings": { "properties": { "topics": { "type": "rank_features" }, "negative_reviews" : { "type": "rank_features", "positive_score_impact": false } } } } PUT my-index-000001/_doc/1 { "topics": { "politics": 20, "economics": 50.8 }, "negative_reviews": { "1star": 10, "2star": 100 } } PUT my-index-000001/_doc/2 { "topics": { "politics": 5.2, "sports": 80.1 }, "negative_reviews": { "1star": 1, "2star": 10 } } GET my-index-000001/_search { "query": { "rank_feature": { "field": "topics.politics" } } } GET my-index-000001/_search { "query": { "rank_feature": { "field": "negative_reviews.1star" } } } GET my-index-000001/_search { "query": { "term": { "topics": "economics" } } }
排序特征字段必须使用 |
|
与分数负相关的排序特征需要声明它 |
|
排序特征字段必须是具有字符串键和严格正数值的哈希 |
|
此查询根据文档与 “政治” 主题的相关程度对其进行排序。 |
|
此查询根据文档收到的 “1星” 评价数量的反比对其进行排序。 |
|
此查询返回在 “topics” 字段中存储 “economics” 特征的文档。 |
rank_features
字段仅支持单值特征和严格正值。多值字段和零值或负值将被拒绝。
rank_features
字段不支持排序或聚合,并且只能使用 rank_feature
或 term
查询进行查询。
对 rank_features
字段的 term
查询是通过将匹配的存储特征值乘以提供的 boost
来评分的。
rank_features
字段仅保留 9 个有效位用于精度,这转化为大约 0.4% 的相对误差。
与分数负相关的排序特征应将 positive_score_impact
设置为 false
(默认为 true
)。这将由 rank_feature
查询使用,以修改评分公式,使得分数随着特征值的增加而减少,而不是增加。