2016-12-16 50 views
2

我需要延遲查詢(或過濾)時使用的查詢令牌。我可以在應用程序級別上做到這一點,但我想知道elasticsearch是否提供了一個開箱即用的解決方案。查詢時刻的延遲令牌

我使用ES 1.7.5(服務)

回答

1

默認elasticsearch將使用在索引時間和查詢時間相同的分析儀,但它可以指定將只在查詢中使用的search_analyzer時間。

讓我們來看看下面的例子:

# First we define an analyzer which will fold non ascii characters called `latinize`. 
PUT books 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "latinize": { 
      "tokenizer": "standard", 
      "filter": ["asciifolding"] 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "book": { 
     "properties": { 
     "name": { 
      "type": "string", 
      "analyzer": "standard",  # We use the standard analyzer at index time. 
      "search_analyzer": "latinize" # But we use the latinize analyzer at query time. 
     } 
     } 
    } 
    } 
} 

# Now let's create a document and search for it with a non latinized string. 
POST books/book 
{ 
    "name": "aaoaao" 
} 

POST books/_search 
{ 
    "query": { 
    "match": { 
     "name": "ääöääö" 
    } 
    } 
} 

和BAM!有我們的文件。

{ 
    "took": 3, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 1, 
    "max_score": 0.30685282, 
    "hits": [ 
     { 
     "_index": "books", 
     "_type": "book", 
     "_id": "AVkIXdNyDpmDHTvI6Cp1", 
     "_score": 0.30685282, 
     "_source": { 
      "name": "aaoaao" 
     } 
     } 
    ] 
    } 
} 
+0

謝謝你的時間!是的,我意識到分析中的不同階段,但事實是,asciifolding會刪除口音,它是否會通過縮寫,例如希臘字符? – alkis

+1

這應該可以通過[ICU插件](https://www.elastic.co/guide/en/elasticsearch/guide/current/character-folding.html)來實現。 – lukad