or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

admin-operations.mdcore-client.mddocument-processing.mdindex.mdsearch-operations.mdsolrcloud-support.mdutilities.md

admin-operations.mddocs/

0

# Administrative Operations

1

2

Core administration capabilities for managing Solr cores including creation, status monitoring, reloading, renaming, swapping, and unloading operations.

3

4

## Capabilities

5

6

### Core Administration Client

7

8

Administrative client for managing Solr cores through the Core Admin API.

9

10

```python { .api }

11

class SolrCoreAdmin:

12

def __init__(self, url, *args, **kwargs):

13

"""

14

Initialize a Solr Core Admin client.

15

16

Parameters:

17

- url (str): Full URL to Solr admin cores endpoint (e.g., 'http://localhost:8983/solr/admin/cores')

18

- *args, **kwargs: Additional arguments passed to parent class

19

"""

20

```

21

22

Usage:

23

24

```python

25

import pysolr

26

27

# Create admin client

28

admin = pysolr.SolrCoreAdmin('http://localhost:8983/solr/admin/cores')

29

```

30

31

### Core Status

32

33

Get status information for one or all Solr cores including configuration, statistics, and health information.

34

35

```python { .api }

36

def status(self, core=None):

37

"""

38

Get core status information.

39

40

Parameters:

41

- core (str, optional): Specific core name to get status for. If None, returns status for all cores

42

43

Returns:

44

str: XML response containing core status information

45

46

Raises:

47

SolrError: If status request fails

48

"""

49

```

50

51

Usage:

52

53

```python

54

# Get status for all cores

55

all_status = admin.status()

56

print("All cores status:", all_status)

57

58

# Get status for specific core

59

core_status = admin.status(core='my_core')

60

print("Core status:", core_status)

61

```

62

63

### Core Creation

64

65

Create new Solr cores with specified configuration and schema files.

66

67

```python { .api }

68

def create(self, name, instance_dir=None, config="solrconfig.xml", schema="schema.xml"):

69

"""

70

Create a new Solr core.

71

72

Parameters:

73

- name (str): Name for the new core

74

- instance_dir (str, optional): Instance directory path. Defaults to core name if not specified

75

- config (str): Configuration file name (default: "solrconfig.xml")

76

- schema (str): Schema file name (default: "schema.xml")

77

78

Returns:

79

str: XML response from core creation

80

81

Raises:

82

SolrError: If core creation fails

83

"""

84

```

85

86

Usage:

87

88

```python

89

# Create core with default settings

90

response = admin.create('new_core')

91

print("Core created:", response)

92

93

# Create core with custom configuration

94

response = admin.create(

95

name='custom_core',

96

instance_dir='/path/to/core/instance',

97

config='custom-solrconfig.xml',

98

schema='custom-schema.xml'

99

)

100

print("Custom core created:", response)

101

```

102

103

### Core Reloading

104

105

Reload Solr cores to apply configuration changes without restarting the server.

106

107

```python { .api }

108

def reload(self, core):

109

"""

110

Reload a Solr core to apply configuration changes.

111

112

Parameters:

113

- core (str): Name of the core to reload

114

115

Returns:

116

str: XML response from core reload

117

118

Raises:

119

SolrError: If core reload fails

120

"""

121

```

122

123

Usage:

124

125

```python

126

# Reload a core after configuration changes

127

response = admin.reload('my_core')

128

print("Core reloaded:", response)

129

```

130

131

### Core Renaming

132

133

Rename existing Solr cores to new names.

134

135

```python { .api }

136

def rename(self, core, other):

137

"""

138

Rename a Solr core.

139

140

Parameters:

141

- core (str): Current name of the core

142

- other (str): New name for the core

143

144

Returns:

145

str: XML response from core rename

146

147

Raises:

148

SolrError: If core rename fails

149

"""

150

```

151

152

Usage:

153

154

```python

155

# Rename a core

156

response = admin.rename('old_core_name', 'new_core_name')

157

print("Core renamed:", response)

158

```

159

160

### Core Swapping

161

162

Swap the names of two existing Solr cores, effectively switching their identities.

163

164

```python { .api }

165

def swap(self, core, other):

166

"""

167

Swap two Solr cores (exchange their names).

168

169

Parameters:

170

- core (str): Name of the first core

171

- other (str): Name of the second core

172

173

Returns:

174

str: XML response from core swap

175

176

Raises:

177

SolrError: If core swap fails

178

"""

179

```

180

181

Usage:

182

183

```python

184

# Swap two cores (useful for blue-green deployments)

185

response = admin.swap('core_blue', 'core_green')

186

print("Cores swapped:", response)

187

```

188

189

### Core Unloading

190

191

Unload Solr cores from memory while preserving their data and configuration on disk.

192

193

```python { .api }

194

def unload(self, core):

195

"""

196

Unload a Solr core from memory.

197

198

Parameters:

199

- core (str): Name of the core to unload

200

201

Returns:

202

str: XML response from core unload

203

204

Raises:

205

SolrError: If core unload fails

206

"""

207

```

208

209

Usage:

210

211

```python

212

# Unload a core from memory

213

response = admin.unload('unused_core')

214

print("Core unloaded:", response)

215

```

216

217

### Unsupported Operations

218

219

Some operations are not available in certain Solr versions.

220

221

```python { .api }

222

def load(self, core):

223

"""

224

Load a Solr core (not implemented).

225

226

Parameters:

227

- core (str): Name of the core to load

228

229

Raises:

230

NotImplementedError: Always raised as this operation is not supported in Solr 1.4 and below

231

"""

232

```

233

234

## Complete Administrative Workflow Example

235

236

```python

237

import pysolr

238

239

# Initialize admin client

240

admin = pysolr.SolrCoreAdmin('http://localhost:8983/solr/admin/cores')

241

242

try:

243

# Check current status

244

print("Checking current cores...")

245

status = admin.status()

246

print("Current status:", status)

247

248

# Create a new core

249

print("Creating new core...")

250

create_response = admin.create(

251

name='test_core',

252

config='solrconfig.xml',

253

schema='managed-schema'

254

)

255

print("Core created successfully")

256

257

# Verify core was created

258

core_status = admin.status(core='test_core')

259

print("New core status:", core_status)

260

261

# Reload core (e.g., after configuration changes)

262

print("Reloading core...")

263

reload_response = admin.reload('test_core')

264

print("Core reloaded successfully")

265

266

# Create another core for swapping demo

267

admin.create('test_core_2')

268

269

# Swap cores

270

print("Swapping cores...")

271

swap_response = admin.swap('test_core', 'test_core_2')

272

print("Cores swapped successfully")

273

274

# Unload cores when done

275

print("Cleaning up...")

276

admin.unload('test_core')

277

admin.unload('test_core_2')

278

print("Cores unloaded successfully")

279

280

except pysolr.SolrError as e:

281

print(f"Admin operation failed: {e}")

282

```

283

284

## Error Handling

285

286

Administrative operations can fail for various reasons and should include proper error handling:

287

288

```python

289

import pysolr

290

291

admin = pysolr.SolrCoreAdmin('http://localhost:8983/solr/admin/cores')

292

293

try:

294

# Attempt to create a core

295

admin.create('my_core')

296

except pysolr.SolrError as e:

297

if 'already exists' in str(e).lower():

298

print("Core already exists, skipping creation")

299

else:

300

print(f"Failed to create core: {e}")

301

raise

302

303

try:

304

# Attempt to reload a core

305

admin.reload('nonexistent_core')

306

except pysolr.SolrError as e:

307

print(f"Core reload failed: {e}")

308

# Handle missing core or configuration errors

309

310

try:

311

# Attempt unsupported operation

312

admin.load('some_core')

313

except NotImplementedError as e:

314

print(f"Operation not supported: {e}")

315

```