Elasticsearch: indexing और search visibility को समझें
जानें कि mapping, shards और refresh कैसे मिलकर काम करते हैं और सफल write तुरंत search में क्यों नहीं दिख सकता।
Elasticsearch: indexing और search visibility को समझें
Elasticsearch में सफल write हमेशा तुरंत search result में नहीं दिखता। दस्तावेज़ को उसके mapping के अनुसार analyze और index किया जाता है, shard में रखा जाता है, और refresh के बाद हाल के बदलाव search के लिए उपलब्ध होते हैं। यह क्रम समझने से field type चुनना और write के तुरंत बाद नतीजा न मिलने की जाँच करना आसान होता है। यह परिचय 23 नवंबर 2026 को देखे गए Elastic के आधिकारिक दस्तावेज़ पर आधारित है; उदाहरण समझाने के लिए हैं और किसी cluster पर चलाए नहीं गए।
Documents, mapping और settings
Index संबंधित JSON documents को रखने और खोजने की इकाई है। Mapping field types और indexing का तरीका बताता है; settings shard count और refresh interval नियंत्रित करती हैं। text को analyzer शब्दों में बाँटता है, इसलिए यह full-text search के लिए है। keyword पूरा मान रखता है, इसलिए exact filter, sort और aggregation में उपयोगी है। Multi-field एक ही मान के दोनों रूप दे सकता है। Dynamic mapping मान देखकर type का अनुमान लगाता है, जो खोज शुरू करने में सुविधाजनक है, पर तारीख जैसी string या संख्या जैसा ID गलत समझा जा सकता है। उत्पादन में स्पष्ट mapping अधिक नियंत्रण देती है; बाद में field type बदलने के लिए आम तौर पर नया index और reindex करना पड़ता है।
Shards और search में दिखने का समय
हर document एक primary shard का हिस्सा है। Replica shards उसकी प्रतियाँ हैं; वे redundancy बढ़ाते और read searches संभाल सकते हैं। Primary shard की संख्या index बनाते समय तय होती है, replica की संख्या बाद में बदली जा सकती है। डेटा और workload के अनुसार पहले योजना बनाएँ। Elasticsearch near-real-time है: write सफल होने के बाद भी refresh से पहले search बदलाव न देखे। Elastic के दस्तावेज़ में डिफ़ॉल्ट interval Elastic Stack के लिए 1 सेकंड और Elastic Cloud Serverless के लिए 5 सेकंड है; settings और search-idle व्यवहार इसे प्रभावित करते हैं।
सामान्यतः refresh छोड़ दें। किसी खास प्रक्रिया में जवाब से पहले नई लिखी चीज़ खोजनी हो तो refresh=wait_for अगली refresh तक प्रतीक्षा करता है। refresh=true तत्काल refresh कराता है, पर बार-बार ऐसा करने से छोटे segments और indexing, search तथा merge का अतिरिक्त काम बनता है। Automatic refresh बंद हो तो wait_for अनिश्चित समय तक रुक सकता है।
उदाहरण और जाँच
इस उदाहरण में नाम full-text, category और SKU exact values, और price numeric है। यह समझाने का उदाहरण है, चलाया हुआ परीक्षण नहीं:
Sources
[Elasticsearch index fundamentals](https://www.elastic.co/docs/manage-data/data-store/index-basics)
[The refresh parameter](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/refresh-parameter)
[Text field type](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/text)
[Clusters, nodes, and shards](https://www.elastic.co/docs/deploy-manage/distributed-architecture/clusters-nodes-shards)
[Match query](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-match-query)