Repository navigation
Expand file tree
/
Copy pathinit-solr.sh
More file actions
executable file
·123 lines (104 loc) · 4.09 KB
/
Copy pathinit-solr.sh
File metadata and controls
executable file
·123 lines (104 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
# Ensure mydata directory exists
mkdir -p /mydata
## Download books.csv if not already present
#if [ ! -f /mydata/books.csv ]; then
# wget -O /mydata/books.csv https://raw.githubusercontent.com/apache/solr/main/solr/example/exampledocs/books.csv
#fi
# Download films.json if not already present
if [ ! -f /mydata/films.json ]; then
wget -O /mydata/films.json https://raw.githubusercontent.com/apache/solr/refs/heads/main/solr/example/films/films.json
fi
# Start Solr in background
/opt/solr/bin/solr start -c -z zoo:2181
# Wait for Solr to be up
until curl -s http://localhost:8983/solr/ > /dev/null; do
echo "Waiting for Solr to start..."
sleep 2
done
# Wait for ZooKeeper to be fully ready for SolrCloud operations
echo "Waiting for ZooKeeper to be ready for SolrCloud operations..."
sleep 10
# Wait for cluster state to be ready
until curl -s "http://localhost:8983/solr/admin/collections?action=CLUSTERSTATUS" | grep -q '"responseHeader"'; do
echo "Waiting for SolrCloud cluster to be ready..."
sleep 2
done
# Create the 'books' collection in SolrCloud mode
# Check if collection already exists via Collections API
if ! curl -s "http://localhost:8983/solr/admin/collections?action=LIST" | grep -q '"books"'; then
echo "Creating books collection..."
/opt/solr/bin/solr create -c books -n _default || {
echo "First attempt failed, retrying collection creation..."
sleep 5
/opt/solr/bin/solr create -c books -n _default || {
echo "Collection creation failed twice, but continuing..."
}
}
else
echo "Books collection already exists, skipping creation."
fi
# Wait for collection to be ready
until curl -s "http://localhost:8983/solr/admin/collections?action=LIST" | grep -q '"books"'; do
echo "Waiting for books collection to be ready..."
sleep 2
done
# Create the 'films' collection in SolrCloud mode
# Check if collection already exists via Collections API
if ! curl -s "http://localhost:8983/solr/admin/collections?action=LIST" | grep -q '"films"'; then
echo "Creating films collection..."
/opt/solr/bin/solr create -c films -n _default || {
echo "First attempt failed, retrying collection creation..."
sleep 5
/opt/solr/bin/solr create -c films -n _default || {
echo "Collection creation failed twice, but continuing..."
}
}
else
echo "Films collection already exists, skipping creation."
fi
# Wait for films collection to be ready
until curl -s "http://localhost:8983/solr/admin/collections?action=LIST" | grep -q '"films"'; do
echo "Waiting for films collection to be ready..."
sleep 2
done
# Both fields go in a single "add-field" array. Repeating the key instead
# would leave duplicate JSON members, and the second silently wins - so the
# "name" field was never actually created.
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field": [
{
"name":"name",
"type":"text_general",
"multiValued":false,
"stored":true
},
{
"name":"initial_release_date",
"type":"pdate",
"stored":true
}
]
}' http://localhost:8983/solr/films/schema
## Post the books.csv data
#/opt/solr/bin/solr post -c books /mydata/books.csv
# Post the films.json data
/opt/solr/bin/solr post -c films /mydata/films.json
# Stop background Solr and run in foreground
/opt/solr/bin/solr stop
exec /opt/solr/bin/solr start -c -z zoo:2181 -f