In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to solve the problem that ES query data suddenly becomes empty". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the problem that ES query data suddenly becomes empty".
Basic environment
Elasticsearch version: 6.3.1
Client environment: kibana 6.3.4, Java8 application module. Kibana is mainly used for data query, diagnosis and log consulting, Java8 is the main client, and data insertion and query are implemented by Java.
Case introduction
Use elasticsearch to store the main information of the order. The field in document is basically long or keyword. The order.json file used to create the index is as follows:
{"doc": {"properties": {"id": {"type": "keyword", "index": true}, "status": {"type": "byte", "index": true} "createTime": {"type": "long", "index": true}, "uid": {"type": "long", "index": true}, "payment": {"type": "keyword" "index": true}, "commentStatus": {"type": "byte", "index": true}, "refundStatus": {"type": "byte", "index": true}
One day I found that there was a query function (querying using the payment field alone) that had no data, and this part of the code had not been modified recently. Compared with the R & D environment, the R & D environment is normal, and the same code has no data return in the test environment.
Problem positioning
This field is used in the program using termQuery, as follows:
QueryBuilders.termQuery ("payment", req.getFilter (). GetOrder (). GetPayment ())
Use the command to diagnose the query data on kibana, and no result is returned. The query command is as follows:
GET / order/doc/_search {"query": {"bool": {"must": [{"term": {"payment": "Alipay"}}]}
Query mapping information to see if it is keyword:
GET / order/_mapping/doc
Response returned (only show payment field):
{"order": {"mappings": {"doc": {"properties": {"payment": {"type": "text", "fields": {"keyword": {"type": "keyword" "ignore_above": 256} cause of the problem
According to the results returned by mapping, the field payment, which was originally defined as keyword, is now text, which is why there is no data for the payment field using a termQuery query.
The difference between text and keyword
Keyword does not segment the saved content and does not change the case. It is stored as is and can be indexed by default. Text participles the content and stores it in all lowercase. At the same time, it adds a text.keyword field of type keyword, which is not indexed after 256 characters.
Because the payment field becomes text, the original program uses term query, uses "Alipay", while text stores "alipay", so the data can not be found.
Try to troubleshoot
The value of payment is changed to lowercase
GET / order/doc/_search {"query": {"bool": {"must": [{"term": {"payment": "alipay"}}]}
Or change term query to match query
GET / order/doc/_search {"query": {"bool": {"must": [{"match": {"payment": "alipay"}}]}
The query has data output and meets expectations, and the trial method is effective.
Problem traceability
It is obvious that the type of payment field defined by order.json is keyword, how did it become text?
Because the environment in which this problem occurs is the test environment, the operation of re-deleting index data and then importing it all (a little irregular, but only in the test environment, the production environment will not do so) and the function of re-importing index document data, when es creates an index automatically mapping, the string content of the payment field will become text.
Solution:
1. Delete index
DELETE / order
two。 Re-index according to order.json
PUT / order {"mappings": {"properties": {"id": {"type": "keyword", "index": true}, "status": {"type": "byte" "index": true}, "createTime": {"type": "long", "index": true}, "uid": {"type": "long" "index": true}, "payment": {"type": "keyword", "index": true}, "commentStatus": {"type": "byte" "index": true}, refundStatus: {"type": "byte", "index": true}
3. Trigger program filling data (you can also use bulk)
At this point, I believe you have a deeper understanding of "how to solve the problem that ES query data suddenly becomes empty". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 226
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.