Тип поля подсчета токенов
Поле типа token_count фактически является полем integer, которое принимает строковые значения, анализирует их и затем индексирует количество токенов в строке.
Например:
resp = client.indices.create(
index="my-index-000001",
mappings={
"properties": {
"name": {
"type": "text",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
}
}
}
}
},
)
print(resp)
resp1 = client.index(
index="my-index-000001",
id="1",
document={
"name": "John Smith"
},
)
print(resp1)
resp2 = client.index(
index="my-index-000001",
id="2",
document={
"name": "Rachel Alice Williams"
},
)
print(resp2)
resp3 = client.search(
index="my-index-000001",
query={
"term": {
"name.length": 3
}
},
)
print(resp3) response = client.indices.create(
index: 'my-index-000001',
body: {
mappings: {
properties: {
name: {
type: 'text',
fields: {
length: {
type: 'token_count',
analyzer: 'standard'
}
}
}
}
}
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 1,
body: {
name: 'John Smith'
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 2,
body: {
name: 'Rachel Alice Williams'
}
)
puts response
response = client.search(
index: 'my-index-000001',
body: {
query: {
term: {
'name.length' => 3
}
}
}
)
puts response const response = await client.indices.create({
index: "my-index-000001",
mappings: {
properties: {
name: {
type: "text",
fields: {
length: {
type: "token_count",
analyzer: "standard",
},
},
},
},
},
});
console.log(response);
const response1 = await client.index({
index: "my-index-000001",
id: 1,
document: {
name: "John Smith",
},
});
console.log(response1);
const response2 = await client.index({
index: "my-index-000001",
id: 2,
document: {
name: "Rachel Alice Williams",
},
});
console.log(response2);
const response3 = await client.search({
index: "my-index-000001",
query: {
term: {
"name.length": 3,
},
},
});
console.log(response3); PUT my-index-000001
{
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
}
}
}
}
}
}
PUT my-index-000001/_doc/1
{ "name": "John Smith" }
PUT my-index-000001/_doc/2
{ "name": "Rachel Alice Williams" }
GET my-index-000001/_search
{
"query": {
"term": {
"name.length": 3
}
}
} | Поле | |
| Поле | |
| Этот запрос соответствует только документу, содержащему |
Параметры для полей token_count
Следующие параметры принимаются полями token_count:
| Анализатор, который должен использоваться для анализа строкового значения. Обязательно. Для наилучшей производительности используйте анализатор без фильтров токенов. | |
| | Указывает, должны ли учитываться приращения позиций. Установите в |
| Должно ли поле храниться на диске в формате с шагом по столбцам, чтобы его можно было использовать для сортировки, агрегаций или сценариев? Принимает | |
| Должно ли поле быть доступным для поиска? Принимает | |
| Принимает числовое значение того же | |
| Следует ли хранить значение поля отдельно от поля |
Синтетическое поле _source
Синтетическое поле _source доступно в общем доступе только для индексов TSDB (индексы, в которых index.mode установлено в time_series). Для других индексов синтетическое поле _source находится в технической предварительной версии. Функции в технической предварительной версии могут быть изменены или удалены в будущих выпусках. Elastic будет работать над исправлением любых проблем, но функции в технической предварительной версии не подпадают под гарантию поддержки официальных функций в общем доступе.
Поля token_count поддерживают синтетическое _source в их конфигурации по умолчанию.
© 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/token-count.html
|
|