Elasticsearch URL问题排查:v2迁移至v6后请求返回空结果
Hey there, let's walk through the most likely reasons your node4:9200/search/all/_search request is returning empty results post-migration—Elasticsearch 6.x introduced several breaking changes that often trip up migrations from 2.x. Here's what to check step by step:
1. Verify Index & Type Structure (Biggest Culprit!)
Elasticsearch 6.x enforces one type per index (a hard break from 2.x, which allowed multiple types). If your original search index had multiple document types, the migration might have altered how your all type is stored:
- Run this command to check the current mapping of your
searchindex:
Look for theGET node4:9200/search/_mappingalltype in the response. If it doesn't exist, your documents might have been migrated to the default_doctype instead. Try queryingnode4:9200/search/_doc/_searchto see if that returns data. - If you used a migration tool like
_reindex, double-check that you explicitly included thealltype in your source parameters—otherwise, it might have been skipped or merged incorrectly.
2. Check Query Syntax Compatibility
ES 6.x deprecated or removed several old query constructs that worked in 2.x. Even if your query doesn't throw an error, it might not match any documents:
- Start with a dead-simple test query to rule out syntax issues:
If this returns results, your original query body is using outdated syntax. For example:GET node4:9200/search/all/_search?q=*- Replace deprecated
filteredqueries withbool+filterclauses. - Ensure
not_analyzedfields (from 2.x) are mapped askeywordtypes in 6.x—termqueries ontextfields won't match exact values like they did onnot_analyzed.
- Replace deprecated
3. Confirm Data Migration Completeness
It's possible your documents never made it to the 6.x cluster at all:
- Check the total number of documents in the
searchindex:
Compare this number to your old 2.x cluster. If it's 0 or drastically lower, re-run your migration process (whether viaGET node4:9200/search/_count_reindex, Logstash, or another tool) and verify that the source index/type is correctly specified. - If you used snapshot/restore, make sure you restored the entire
searchindex, not just a subset.
4. Validate Index Aliases
If search was an alias pointing to multiple indices in 2.x, your alias configuration might not have been updated for 6.x:
- Check what the
searchalias points to:
If it's pointing to an empty index or an index that doesn't include theGET node4:9200/_alias/searchalltype, update the alias to target the correct index with your data.
5. Check Field Mapping & Analyzers
Changes to default analyzers or field mappings can break query matches even if data exists:
- For fields you're querying, confirm their mapping in 6.x matches the 2.x version. For example, if a field was
not_analyzedin 2.x, it should betype: keywordin 6.x. - Test a specific field match to see if it works:
If this doesn't return a document you know exists, the field's mapping or analyzer has likely changed during migration.GET node4:9200/search/all/_search { "query": { "term": { "your_field_name": "expected_value" } } }
Start with the first two checks—they'll cover 90% of cases I've seen with this exact issue. Let me know if you find something unexpected in the responses!
内容的提问来源于stack exchange,提问作者Čamo

