1
votes

I wish to improve search in an ES index by searching for greek letter synonyms (α as alpha). In this post they use a 'regular' analyzer that would require to re-index all of the data.

My question is how to accomplish this synonym search using a search_analyzer only.

Thanks!

Here is an example of two entries and a search query, I would like this single query to return both docs

PUT test_ind/_doc/2
{
    "title" : "α" 
}

PUT test_ind/_doc/1
{
    "title" : "alpha"       
}

POST test_ind/_search
{
  "query": {
    "term": {
    "title": "alpha"

  }}
}

expected output:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_ind",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "title" : "alpha"
        }
      },
      {
        "_index" : "test_ind",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "title" : "α"
        }
      }
    ]
  }
}
1
you can use an analyzer at search or index. but at index time will be far faster in the long run. You don't need to reindex all of the data. you'd just need to add another field that uses the analyzer and include that field in your search. then you're just adding a field, which is straight forwardbryan60
Please give an example of one or two values (documents) and one or two query inputsAlkis Kalogeris
@AlkisKalogeris added example. I'm able to accomplish this with analyzer, but not while using search_analyzer onlyRoy Granit

1 Answers

0
votes
PUT test_ind
{
  "settings": {
    "analysis": {
      "analyzer": {
        "synonyms": {
          "tokenizer": "whitespace",
          "filter": [
            "synonym"
          ]
        }
      },
      "filter": {
        "synonym": {
          "type": "synonym",
          "synonyms": [
            "α,alpha"
          ]
        }
      }
    }
  }
}

PUT test_ind/_doc/2
{
    "title" : "α" 
}

PUT test_ind/_doc/1
{
    "title" : "alpha"       
}

POST test_ind/_search
{
  "query": {
    "match": {
      "title": {
        "query": "alpha",
        "analyzer": "synonyms"
      }
    }
  }
}

And if your index already exists you need to add the analyzer (no reindexing required) as shown here

POST /test_ind/_close

PUT /test_ind/_settings
{
  "analysis": {
    "analyzer": {
      "synonyms": {
        "tokenizer": "whitespace",
        "filter": [
          "synonym"
        ]
      }
    },
    "filter": {
      "synonym": {
        "type": "synonym",
        "synonyms": [
          "α,alpha"
        ]
      }
    }
  }
}

POST /test_ind/_open