Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Отображение ›Параметры отображения

term_vector

Вектора терминов содержат информацию о терминах, полученных в процессе анализа, включая:

  • список терминов.
  • положение (или порядок) каждого термина.
  • начальное и конечное смещение символов, сопоставляющие термин его источнику в исходной строке.
  • платные нагрузки (если они доступны) — пользовательские двоичные данные, связанные с каждым положением термина.

Эти векторы терминов могут храниться для последующего извлечения по определённому документу.

Параметр term_vector принимает:

no

Векторы терминов не хранятся. (по умолчанию)

yes

Хранятся только термины в поле.

with_positions

Хранятся термины и позиции.

with_offsets

Хранятся термины и смещения символов.

with_positions_offsets

Хранятся термины, позиции и смещения символов.

with_positions_payloads

Хранятся термины, позиции и платные нагрузки.

with_positions_offsets_payloads

Хранятся термины, позиции, смещения и платные нагрузки.

Для быстрого выделения векторов требуется with_positions_offsets. API векторов терминов может извлечь всё сохранённое.

Установление with_positions_offsets удвоит размер индекса поля.

resp = client.indices.create(
    index="my-index-000001",
    mappings={
        "properties": {
            "text": {
                "type": "text",
                "term_vector": "with_positions_offsets"
            }
        }
    },
)
print(resp)

resp1 = client.index(
    index="my-index-000001",
    id="1",
    document={
        "text": "Quick brown fox"
    },
)
print(resp1)

resp2 = client.search(
    index="my-index-000001",
    query={
        "match": {
            "text": "brown fox"
        }
    },
    highlight={
        "fields": {
            "text": {}
        }
    },
)
print(resp2)
response = client.indices.create(
  index: 'my-index-000001',
  body: {
    mappings: {
      properties: {
        text: {
          type: 'text',
          term_vector: 'with_positions_offsets'
        }
      }
    }
  }
)
puts response

response = client.index(
  index: 'my-index-000001',
  id: 1,
  body: {
    text: 'Quick brown fox'
  }
)
puts response

response = client.search(
  index: 'my-index-000001',
  body: {
    query: {
      match: {
        text: 'brown fox'
      }
    },
    highlight: {
      fields: {
        text: {}
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "my-index-000001",
  mappings: {
    properties: {
      text: {
        type: "text",
        term_vector: "with_positions_offsets",
      },
    },
  },
});
console.log(response);

const response1 = await client.index({
  index: "my-index-000001",
  id: 1,
  document: {
    text: "Quick brown fox",
  },
});
console.log(response1);

const response2 = await client.search({
  index: "my-index-000001",
  query: {
    match: {
      text: "brown fox",
    },
  },
  highlight: {
    fields: {
      text: {},
    },
  },
});
console.log(response2);
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "text": {
        "type":        "text",
        "term_vector": "with_positions_offsets"
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "text": "Quick brown fox"
}

GET my-index-000001/_search
{
  "query": {
    "match": {
      "text": "brown fox"
    }
  },
  "highlight": {
    "fields": {
      "text": {} 
    }
  }
}

По умолчанию для поля text будет использоваться быстрый выделение векторов, так как векторы терминов включены.

© 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/term-vector.html

Spec-Zone.ru

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