Rank feature field type

Rank feature field type

A rank_feature field can index numbers so that they can later be used to boost documents in queries with a rank_feature query.

  1. resp = client.indices.create(
  2. index="my-index-000001",
  3. mappings={
  4. "properties": {
  5. "pagerank": {
  6. "type": "rank_feature"
  7. },
  8. "url_length": {
  9. "type": "rank_feature",
  10. "positive_score_impact": False
  11. }
  12. }
  13. },
  14. )
  15. print(resp)
  16. resp1 = client.index(
  17. index="my-index-000001",
  18. id="1",
  19. document={
  20. "pagerank": 8,
  21. "url_length": 22
  22. },
  23. )
  24. print(resp1)
  25. resp2 = client.search(
  26. index="my-index-000001",
  27. query={
  28. "rank_feature": {
  29. "field": "pagerank"
  30. }
  31. },
  32. )
  33. print(resp2)
  1. response = client.indices.create(
  2. index: 'my-index-000001',
  3. body: {
  4. mappings: {
  5. properties: {
  6. pagerank: {
  7. type: 'rank_feature'
  8. },
  9. url_length: {
  10. type: 'rank_feature',
  11. positive_score_impact: false
  12. }
  13. }
  14. }
  15. }
  16. )
  17. puts response
  18. response = client.index(
  19. index: 'my-index-000001',
  20. id: 1,
  21. body: {
  22. pagerank: 8,
  23. url_length: 22
  24. }
  25. )
  26. puts response
  27. response = client.search(
  28. index: 'my-index-000001',
  29. body: {
  30. query: {
  31. rank_feature: {
  32. field: 'pagerank'
  33. }
  34. }
  35. }
  36. )
  37. puts response
  1. const response = await client.indices.create({
  2. index: "my-index-000001",
  3. mappings: {
  4. properties: {
  5. pagerank: {
  6. type: "rank_feature",
  7. },
  8. url_length: {
  9. type: "rank_feature",
  10. positive_score_impact: false,
  11. },
  12. },
  13. },
  14. });
  15. console.log(response);
  16. const response1 = await client.index({
  17. index: "my-index-000001",
  18. id: 1,
  19. document: {
  20. pagerank: 8,
  21. url_length: 22,
  22. },
  23. });
  24. console.log(response1);
  25. const response2 = await client.search({
  26. index: "my-index-000001",
  27. query: {
  28. rank_feature: {
  29. field: "pagerank",
  30. },
  31. },
  32. });
  33. console.log(response2);
  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "pagerank": {
  6. "type": "rank_feature"
  7. },
  8. "url_length": {
  9. "type": "rank_feature",
  10. "positive_score_impact": false
  11. }
  12. }
  13. }
  14. }
  15. PUT my-index-000001/_doc/1
  16. {
  17. "pagerank": 8,
  18. "url_length": 22
  19. }
  20. GET my-index-000001/_search
  21. {
  22. "query": {
  23. "rank_feature": {
  24. "field": "pagerank"
  25. }
  26. }
  27. }

Rank feature fields must use the rank_feature field type

Rank features that correlate negatively with the score need to declare it

rank_feature fields only support single-valued fields and strictly positive values. Multi-valued fields and negative values will be rejected.

rank_feature fields do not support querying, sorting or aggregating. They may only be used within rank_feature queries.

rank_feature fields only preserve 9 significant bits for the precision, which translates to a relative error of about 0.4%.

Rank features that correlate negatively with the score should set positive_score_impact to false (defaults to true). This will be used by the rank_feature query to modify the scoring formula in such a way that the score decreases with the value of the feature instead of increasing. For instance in web search, the url length is a commonly used feature which correlates negatively with scores.