如何在Elasticsearch中在查询时间而不是索引时间应用同义词
根据elasticsearch参考文档,可以:
可以在索引时间或查询时间应用扩展。每个都有优点(⬆)︎和缺点(⬇)︎。何时使用取决于性能与灵活性。
优点和缺点都是有意义的,对于我的特定用途,我想 在查询时
使用同义词。我的用例是,我希望允许系统中的管理员用户管理这些同义词,而不必在更新时重新索引所有内容。另外,我想不关闭并重新打开索引就这样做。
我认为这是可能的主要原因是此优势:
(⬆)︎无需重新编制文档索引即可更新同义词规则。
但是,我找不到任何描述 如何 在查询时间而不是索引时间应用同义词的文档。
要使用一个具体的示例,如果我执行以下操作(示例被盗,并从reference进行了稍微修改),似乎这将在索引时间应用同义词:
/* NOTE: This was all run against elasticsearch 1.5 (if that matters; documentation is identical in 2.x) */
// Create our synonyms filter and analyzer on the index
PUT my_synonyms_test
{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"queen,monarch"
]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
}
}
// Create a mapping that uses this analyzer
PUT my_synonyms_test/rulers/_mapping
{
"properties": {
"name": {
"type": "string"
},
"title": {
"type": "string",
"analyzer": "my_synonyms"
}
}
}
// Some data
PUT my_synonyms_test/rulers/1
{
"name": "Elizabeth II",
"title": "Queen"
}
// A query which utilises the synonyms
GET my_synonyms_test/rulers/_search
{
"query": {
"match": {
"title": "monarch"
}
}
}
// And we get our expected result back:
{
"took": 42,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.4142135,
"hits": [
{
"_index": "my_synonyms_test",
"_type": "rulers",
"_id": "1",
"_score": 1.4142135,
"_source": {
"name": "Elizabeth II",
"title": "Queen"
}
}
]
}
}
所以我的问题是:如何修改上面的示例,以便在 查询时 使用同义词?