Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Mapping ›Типы данных полей

Тип поля 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, которые отрицательно коррелируют с результатом, должны быть объявлены

Поля rank features должны быть хэш-таблицей со строковыми ключами и строго положительными числовыми значениями

Этот запрос ранжирует документы по тому, насколько они относятся к теме «политика».

Этот запрос ранжирует документы обратно пропорционально количеству отзывов «1 звезда».

Этот запрос возвращает документы, в которых признак «экономика» хранится в поле «темы».

Поля типа rank_features поддерживают только однозначные признаки и строго положительные значения. Многозначные поля и нулевые или отрицательные значения будут отклонены.

Для полей типа rank_features не поддерживается сортировка или агрегирование, и они могут быть запрошены только с помощью rank_feature или term запросов.

term запросы к полям типа rank_features оцениваются путем умножения соответствующего сохраненного значения признака на указанное значение boost.

Поля типа rank_features сохраняют только 9 значимых битов для точности, что соответствует относительной ошибке около 0,4%.

Признаки rank features, которые отрицательно коррелируют с результатом, должны установить positive_score_impact в значение false (по умолчанию true). Это будет использовано запросом rank_feature для изменения формулы подсчета таким образом, что результирующий балл уменьшается с ростом значения признака вместо увеличения.

© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/rank-features.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API