Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the maximum number of characters supported in a single field of Elasticsearch

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what is the maximum number of characters supported in a single field of Elasticsearch". In daily operation, I believe many people have doubts about the maximum number of characters supported in a single field of Elasticsearch. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the maximum number of characters supported by Elasticsearch in a single field?" Next, please follow the editor to study!

01

What is the role of ignore_above?

ES is used for setting beyond the set character, it is not indexed or stored.

Strings longer than the ignore_above setting will not be indexed or stored.

02

Ignore_above usage

PUT ali_test

{

"mappings": {

"ali_type": {

"properties": {

"url": {

"type": "keyword"

"ignore_above": 256

}

"url_long": {

"type": "keyword"

}

"url_long_long": {

"type": "keyword"

"ignore_above": 32766

}

}

}

}

}

03

When the character exceeds the given length, can it be saved?

Verify the table name for the url,url_long,url_long_long3 fields set in mapping above. Url with more than 256characters can be saved.

3.1 keyword type, normal length verification

The length of the inserted url is: 1705 characters, as follows:

Post ali_test/ali_type/1

{

"url": "1705 character url"

}

Url reference address: http://t.cn/zH6FHG7

Search:

GET ali_test/ali_type/_search

{

"query": {

"term": {

"url": "1705 character url"

}

}

}

Return the result:

{

"took": 1

"timed_out": false

"_ shards": {

"total": 5

"successful": 5

"failed": 0

}

"hits": {

"total": 0

"max_score": null

"hits": []

}

}

Conclusion:

1705 characters, url, url_long, url_long_long can be saved, you can view the results through the head plug-in.

However, url term retrieval cannot retrieve the returned results because the url field is set to "ignore_above": 256, which causes it not to be indexed after more than 256 characters.

3.2 for keyword types, critical length verification

For a document with 32767 characters in post, the error is as follows:

{

"error": {

"root_cause": [

{

"type": "illegal_argument_exception"

"reason": "Document contains at least one immense term in field= url_long" (whose UTF8 encoding is longer than the max length 32766), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is:'[104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 103, 111, 111, 108,101,46,99,111,109,47,115,101,97,114,99,104,63,104], original message: bytes can be at most 32766 in length; got 32767 "

}

]

"caused_by": {

"type": "max_bytes_length_exceeded_exception"

"reason": "max_bytes_length_exceeded_exception: bytes can be at most 32766 in length; got 32767"

}

}

Status: 400

}

After 32766 characters of post, it can be submitted successfully. The returned result is as follows:

{

"_ index": "ali_test"

"_ type": "ali_type"

"_ id": "2000"

"_ version": 1

"result": "created"

"_ shards": {

"total": 2

"successful": 2

"failed": 0

}

"created": true

}

Conclusion: the maximum supported length of keyword type is-32766 characters of UTF-8 type.

In other words, the maximum supported length for term exact matching is 32766 UTF-8 characters.

04

What is the difference in the number of storage characters between text type and keyword type?

Text type: supports word segmentation and full-text search, but does not support aggregation and sorting operations. Suitable for large field storage, such as article details, content fields, etc.

Keyword type: exact matching, aggregation and sorting operations are supported. Suitable for accurate field matching, such as url, name, title and other fields.

Generally speaking, text and keyword coexist. Set mapping as follows:

{

"mappings": {

"ali_type": {

"properties": {

"title_v1": {

"analyzer": "ik_max_word"

"type": "text"

"term_vector": "with_positions_offsets"

"fields": {

"keyword": {

"ignore_above": 256

"type": "keyword"

}

}

}

}

}

}

}

At this point, the study of "what is the maximum number of characters supported in a single field of Elasticsearch" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report