Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load and use synonym.txt file on ElasticSearch

I am using the following docker-compose.yml to create an ElasticSearch cluster:

version: '3.3'
services:
  elasticsearch1:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
    container_name: elasticsearch1
    environment:
      ...
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
      - ${PWD}/data/thesaurus/output:/usr/share/elasticsearch/config/extra
    ports:
      - 9200:9200
    networks:
      - elastic
  elasticsearch2:
    ...
volumes:
  data01:
    driver: local
  data02:
    driver: local
networks:
  elastic:
    driver: bridge

My index contains:

  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 1,
    "index" : {
      "analysis" : {
          "filter" : {
              "synonym" : {
                  "type" : "synonym", 
                  "synonyms_path" : "extra/synonym.txt"
              }
          },
          "analyzer" : {
              "synonym" : {
                  "tokenizer" : "standard",
                  "filter" : ["lowercase", "synonym"] 
              }
          }
      }
    }

When I try to PUT my data, I get:

{'error': {'root_cause': [{'type': 'illegal_argument_exception', 'reason': 'failed to build synonyms'}], 'type': 'illegal_argument_exception', 'reason': 'failed to build synonyms', 'caused_by': {'type': 'i_o_exception', 'reason': 'Is a directory'}}, 'status': 400}

Interestingly, when I run: docker exec elasticsearch1 cat config/extra/synonym.txt, I get the error: cat: config/extra/synonym.txt: Is a directory

How do I load and use the synonym.txt file?

like image 935
Leo Avatar asked Jan 02 '26 02:01

Leo


1 Answers

As written in elastic documentation - here:

The above configures a synonym filter, with a path of analysis/synonym.txt (relative to the config location). The synonym analyzer is then configured with the filter.

So you replace the synonyms_path :

"synonyms_path" : "/extra/synonym.txt" 

in:

"synonyms_path" : "extra/synonym.txt"
like image 144
Lupanoide Avatar answered Jan 04 '26 01:01

Lupanoide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!