Rank Feature 字段类型

编辑

rank_feature 字段可以索引数字,以便稍后在使用 rank_feature 查询的查询中提升文档。

resp = client.indices.create(
    index="my-index-000001",
    mappings={
        "properties": {
            "pagerank": {
                "type": "rank_feature"
            },
            "url_length": {
                "type": "rank_feature",
                "positive_score_impact": False
            }
        }
    },
)
print(resp)

resp1 = client.index(
    index="my-index-000001",
    id="1",
    document={
        "pagerank": 8,
        "url_length": 22
    },
)
print(resp1)

resp2 = client.search(
    index="my-index-000001",
    query={
        "rank_feature": {
            "field": "pagerank"
        }
    },
)
print(resp2)
response = client.indices.create(
  index: 'my-index-000001',
  body: {
    mappings: {
      properties: {
        pagerank: {
          type: 'rank_feature'
        },
        url_length: {
          type: 'rank_feature',
          positive_score_impact: false
        }
      }
    }
  }
)
puts response

response = client.index(
  index: 'my-index-000001',
  id: 1,
  body: {
    pagerank: 8,
    url_length: 22
  }
)
puts response

response = client.search(
  index: 'my-index-000001',
  body: {
    query: {
      rank_feature: {
        field: 'pagerank'
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "my-index-000001",
  mappings: {
    properties: {
      pagerank: {
        type: "rank_feature",
      },
      url_length: {
        type: "rank_feature",
        positive_score_impact: false,
      },
    },
  },
});
console.log(response);

const response1 = await client.index({
  index: "my-index-000001",
  id: 1,
  document: {
    pagerank: 8,
    url_length: 22,
  },
});
console.log(response1);

const response2 = await client.search({
  index: "my-index-000001",
  query: {
    rank_feature: {
      field: "pagerank",
    },
  },
});
console.log(response2);
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "pagerank": {
        "type": "rank_feature" 
      },
      "url_length": {
        "type": "rank_feature",
        "positive_score_impact": false 
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "pagerank": 8,
  "url_length": 22
}

GET my-index-000001/_search
{
  "query": {
    "rank_feature": {
      "field": "pagerank"
    }
  }
}

Rank Feature 字段必须使用 rank_feature 字段类型

与得分负相关的 Rank Feature 需要声明它

rank_feature 字段仅支持单值字段和严格正值。多值字段和负值将被拒绝。

rank_feature 字段不支持查询、排序或聚合。它们只能在 rank_feature 查询中使用。

rank_feature 字段仅保留 9 位有效位数以进行精度计算,这转换为大约 0.4% 的相对误差。

与得分负相关的 Rank Feature 应将 positive_score_impact 设置为 false(默认为 true)。这将被 rank_feature 查询用来修改评分公式,使其得分随着特征值的增加而降低而不是增加。例如,在网络搜索中,URL 长度是一个常用的特征,它与得分负相关。