查询Synomys ElasticSearch

时间:2018-05-11 14:07:18

标签: elasticsearch kibana

我用这种方式创建一个带有同义词的新索引:

PUT / test_index2

{
"settings": {
    "index" : {
        "analysis" : {
            "filter" : {
                "synonym" : {
                    "type" : "synonym",
                    "synonyms" : [
                        "mezzo,centro"
                    ]
                }
            }
        }
    }
}

}

当我尝试这个查询时:

{
   "query": 
     {
        "multi_match": 
            {
               "query": "centro",
               "fields": ["content"],
                "analyzer": "synonym"
            }
      }
  }

Kibana给了我这个错误:

  [multi_match] analyzer [synonym] not found

我对弹力的经验不是很有帮助吗?

1 个答案:

答案 0 :(得分:0)

您需要创建一个利用同义词过滤器的自定义分析器

{
"settings": {
    "index" : {
        "analysis" : {
            "analyzer": {                          <-- add this
                "synonym_analyzer": {
                   "type": "custom",
                   "filter": ["synonym"],
                   "tokenizer": "keyword"
                }
            },
            "filter" : {
                "synonym" : {
                    "type" : "synonym",
                    "synonyms" : [
                        "mezzo,centro"
                    ]
                }
            }
        }
    }
}

然后您可以在查询中使用它

{
   "query": 
     {
        "multi_match": 
            {
               "query": "centro",
               "fields": ["content"],
                "analyzer": "synonym_analyzer"   <-- change this
            }
      }
  }