Skip to content

Instantly share code, notes, and snippets.

@TomonoriSoejima
Last active November 6, 2020 12:24
Show Gist options
  • Save TomonoriSoejima/3fbef35906e55656f38da7403532dfe7 to your computer and use it in GitHub Desktop.
Save TomonoriSoejima/3fbef35906e55656f38da7403532dfe7 to your computer and use it in GitHub Desktop.
cloud dictionary upload sample
# note that elasticsearch/config/test.txt should exist

PUT /test
{
  "settings": {
    "analysis": {
      "filter": {
        "my_synonym_filter": {
          "type": "synonym", 
          "synonyms_path": "test.txt"
        }
      },
      "analyzer": {
        "my_synonyms": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "my_synonym_filter" 
          ]
        }
      }
    }
  },
    "mappings": {
    "my_type": {
      "properties": {
        "name": {
          "type": "text",
          "analyzer": "my_synonyms", 
          "search_analyzer": "my_synonyms" 
        }
      }
    }
  }
}




PUT test/my_type/1
{
  "name" : "ringo"
}

PUT test/my_type/2
{
  "name" : "apple"
}

GET test/my_type/_search/
{
  "query": {
    "match": {
        "name": "ringo"
      }
  }
}

# -> 1 doc hits


# add entry "ringo,apple" to test.txt dictionary.



POST test/_close
POST test/_open

GET test/my_type/_search/
{
  "query": {
    "match": {
        "name": "ringo"
      }
  }
}

# -> 2 doc hits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment