Rank Features 字段类型
编辑Rank Features 字段类型
编辑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" } } }
Rank Features 字段必须使用 |
|
与分数负相关的 Rank Features 需要声明。 |
|
Rank Features 字段必须是具有字符串键和严格正数值的哈希。 |
|
此查询根据文档与“政治”主题的相关程度对文档进行排序。 |
|
此查询根据文档收到的“1星”评论数量的倒数对文档进行排序。 |
|
此查询返回在“topics”字段中存储“economics”特征的文档。 |
rank_features
字段仅支持单值特征和严格正值。多值字段和零或负值将被拒绝。
rank_features
字段不支持排序或聚合,并且只能使用 rank_feature
或 term
查询进行查询。
对 rank_features
字段的 term
查询通过将匹配的存储特征值乘以提供的 boost
来评分。
rank_features
字段仅保留 9 位有效数字以实现精度,这相当于约 0.4% 的相对误差。
与分数负相关的 Rank Features 应将 positive_score_impact
设置为 false
(默认为 true
)。rank_feature
查询将使用此功能修改评分公式,以便分数随着特征值的增加而降低而不是增加。