我们title
在索引中存储一个字段,并希望将该字段用于两个目的:
- 我们正在使用 ngram 过滤器进行分析,因此我们可以提供自动完成和即时结果
- 我们希望能够在
title
字段上使用 ASC 排序而不是得分来列出结果。
索引/过滤器/分析器的定义如下:
array(
'number_of_shards' => $this->shards,
'number_of_replicas' => $this->replicas,
'analysis' => array(
'filter' => array(
'nGram_filter' => array(
'type' => 'nGram',
'min_gram' => 2,
'max_gram' => 20,
'token_chars' => array('letter','digit','punctuation','symbol')
)
),
'analyzer' => array(
'index_analyzer' => array(
'type' => 'custom',
'tokenizer' =>'whitespace',
'char_filter' => 'html_strip',
'filter' => array('lowercase','asciifolding','nGram_filter')
),
'search_analyzer' => array(
'type' => 'custom',
'tokenizer' =>'whitespace',
'char_filter' => 'html_strip',
'filter' => array('lowercase','asciifolding')
)
)
)
),
当我们在现场进行排序时,我们遇到的问题是不可预测的结果title
。经过一番搜索后,我们sort
在 ElasticSearch 的手册页末尾找到了这个...(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html# _memory_considerations )
对于基于字符串的类型,排序的字段不应被分析/标记化。
我们如何同时分析该字段并稍后对其进行排序?我们是否需要将字段存储两次,一次使用not_analyzed
才能进行排序?由于该字段_source
还title
以原始状态存储值,因此不能用于排序吗?