Solr电影示例索引异常:索引无结果/仅5条文档求助
Hey there, let's work through your Solr films index issues together — I've run into similar snags when getting started, so let's break down the possible fixes step by step.
1. Fix Your Truncated Schema Update Command
Looking at your curl command for updating the schema:
curl http://localhost:8983/solr/films/schema -X POST -H 'Content-type:application/json' --data-binary '{ "add-field" : { "name":"name", "type":"text_general", "multiValued":false, "stored":true }, "add-fiel...'
The command is truncated at "add-fiel..." — this is a critical issue. Solr requires a valid, complete JSON payload for schema changes. If you're following Steve Rowe's steps, make sure you copy the full JSON snippet (including all closing brackets and any additional field definitions he specifies). Incomplete or malformed JSON will fail silently or partially apply changes, which can break document indexing later.
2. Don't Forget to Import Actual Film Data
Creating the films core and updating the schema only sets up the index structure — you still need to load actual film documents into Solr. If you skipped this step, the 5 documents you see might be default test entries, or partial failed imports.
Depending on the tutorial, you'll likely need to:
- Prepare a CSV/JSON file with your film data (or use the sample data Steve might have provided)
- Use Solr's built-in
posttool to upload the data:bin/post -c films /path/to/your/films-data.json - Or configure the Data Import Handler (DIH) if you're pulling data from a database.
After importing, always run a commit to make the documents visible:
curl http://localhost:8983/solr/films/update?commit=true
3. Check Solr Logs for Hidden Errors
Even though you deleted old logs, new logs are generated in server/logs/ as soon as you restart Solr. Open the latest solr.log file and look for:
- Schema update errors (like invalid JSON syntax)
- Indexing failures (permission issues, mismatched field types in documents)
- Core initialization warnings
For example, if your truncated schema command failed, you'll see lines like ERROR org.apache.solr.schema.SchemaManager - Error parsing JSON schema update with details about the invalid payload. These logs are your best friend for debugging Solr issues!
4. Verify Document Structure Matches Your Schema
If you did import data, make sure your documents align with the fields you defined. For instance, if you added a name field, each document should include a name value (unless you marked it as optional). If your documents have fields that aren't in the schema and Solr's schema is set to strict mode (default in newer versions), those documents will be rejected, leading to fewer indexed docs than expected.
Test indexing a single simple document manually to rule out schema issues:
curl http://localhost:8983/solr/films/update -X POST -H 'Content-type:application/json' --data-binary '[ { "id": "test-film-1", "name": "The Test Movie", "release_year": 2024 } ]' # Commit to make it visible curl http://localhost:8983/solr/films/update?commit=true
Then head to the Solr Admin UI's Query tab and run a simple query (*:*) to see if this test document appears.
5. Ensure Clean Core Creation
Sometimes leftover files from previous core attempts can cause weird behavior. Double-check that you fully removed the server/solr/films/ directory before recreating the core. You can verify by:
- Checking that
server/solr/films/core.propertiesexists and has the correct core name - Opening
server/solr/films/conf/managed-schemato confirm yournamefield (and any others) are present
内容的提问来源于stack exchange,提问作者Choix

