We have tried another approach as recommended by ES documentation 8.10.2 via config maps as well. ES recommendation documents: Custom configuration files and plugins | Elastic Cloud on Kubernetes [2.10] | Elastic and Provisioning of custom configuration files · Issue #1571 · elastic/cloud-on-k8s · GitHub
We are adding a synonyms file for the synonym token filter in Elasticsearch by mounting synonyms file into the configuration directory of Elasticsearch via config map.
The config map has the all synonyms defined inline.
Attaching some code snippets for reference, the code snippet is just for the data node but we have similarly defined master and client nodes in elasticsearch.yml and synonyms file exists on each node as expected.
- configmap.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: synonyms-config
data:
synonyms_en.txt: |
ipod, i-pod, i pod
...
synonyms_fr.txt: |
personal computer => pc
...
- elasticsearch.yml
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: elasticsearch-eck
spec:
version: 8.10.2
volumeClaimDeletePolicy: DeleteOnScaledownOnly
updateStrategy:
changeBudget:
maxSurge: -1
maxUnavailable: 0
http:
service:
spec:
type: ClusterIP
ports:
- name: http
port: 9200
targetPort: 9200
tls:
selfSignedCertificate:
disabled: true
nodeSets:
- name: data
count: 1
config:
node.roles: ["data", "ingest"]
podTemplate:
metadata:
labels:
app: elasticsearch-eck
spec:
volumes:
- name: synonyms-volume
configMap:
name: synonyms-config
initContainers:
- name: configure-sysctl
command: ['sh', '-c', 'sysctl -w vm.max_map_count=262144']
securityContext:
runAsUser: 0
privileged: true
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- elasticsearch-eck
topologyKey: kubernetes.io/hostname
containers:
- name: elasticsearch-eck
volumeMounts:
- name: synonyms-volume
mountPath: /usr/share/elasticsearch/config/dictionaries
env:
- name: ES_JAVA_OPTS
value: "-Xms8g -Xmx8g"
resources:
requests:
cpu: 2000m
memory: 12Gi
limits:
cpu: 8000m
memory: 16Gi
image: "docker.elastic.co/elasticsearch/elasticsearch:8.10.2"
imagePullPolicy: "IfNotPresent"
securityContext:
capabilities:
drop:
- ALL
runAsNonRoot: true
runAsUser: 1000
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: standard
podDisruptionBudget:
spec:
maxUnavailable: 0
selector:
matchLabels:
app: elasticsearch-eck
At "/usr/share/elasticsearch/config/dictionaries" location in our data, client and master nodes, the synonyms file exists with the expected data.
Attaching some screenshot representing files in the ES cluster:
Our index creation definition looks like this:
...
"english_synonym_filter": {
"type": "synonym_graph",
"lenient": true,
"synonyms_path": "/usr/share/elasticsearch/config/dictionaries/synonyms_en.txt"
},
.....
**Note:** We have also tried relative path in the index creation template:
"english_synonym_filter": {
"type": "synonym_graph",
"lenient": true,
"synonyms_path": "dictionaries/synonyms_en.txt"
},
However, we get the no such file exception in both cases.
Error:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "IOException while reading synonyms_path_path: /usr/share/elasticsearch/config/dictionaries/synonyms_fr.txt"
}
],
"type": "illegal_argument_exception",
"reason": "IOException while reading synonyms_path_path: /usr/share/elasticsearch/config/dictionaries/synonyms_fr.txt",
"caused_by": {
"type": "no_such_file_exception",
"reason": "/usr/share/elasticsearch/config/dictionaries/synonyms_fr.txt"
}
},
"status": 400
}