If you want to have multiple Solr indexes using Search API, you need to have a core for each index instance. For my local development stack, I use DDEV. The documentation has a basic example for setting up a Solr service, but I had quite the fun time figuring out how to ensure multiple cores.
After reading the Solr image for Docker, I discovered you can override the container's command and pass additional commands as well. I found the issue "Create multiple collections at startup" from Sep 2017 which summed up my desired outcome. You just need to add this as the command for your container to generate additional cores:
bash -e -c "precreate-core collection1; precreate-core collection2; solr-foreground"
This ensures collection1 and collection2 and could create however many are needed.
To add Solr to your DDEV with multiple cores, here is the docker-composer.solr.yaml you can add to your project
version: '3.6'
services:
solr:
container_name: ddev-${DDEV_SITENAME}-solr
image: solr:6.6
command: 'bash -e -c "precreate-core collection1; precreate-core collection2; solr-foreground"'
restart: "no"
ports:
- 8983
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
com.ddev.app-url: $DDEV_URL
environment:
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=8983
volumes:
- "./solr:/solr-conf"
web:
links:
- solr:$DDEV_HOSTNAME
# Platform.sh hostname alias
- solr:solr.internal
Want more? Sign up for my weekly newsletter