ouc*_*cil 5 sorting elasticsearch elastica
我们title在索引中存储了一个字段,并希望将该字段用于两个目的:
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')
)
)
)
),
Run Code Online (Sandbox Code Playgroud)
当我们对title场地进行排序时,我们遇到的问题是不可预测的结果.在做了一点搜索之后,我们sort在ElasticSearch 的手册页末尾发现了这个...(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html# _memory_considerations)
对于基于字符串的类型,不应分析/标记化排序的字段.
我们怎样才能分析这个领域并在以后对其进行排序?我们是否需要将字段存储两次,并使用一个字段not_analyzed进行排序?由于该字段_source还将title值存储在其原始状态中,是否可以不用于排序?
您可以在Elasticsearch中使用Multi Field Type的内置概念.
multi_field类型允许映射相同值的几个core_types.这可以非常方便,例如,当想要映射字符串类型时,一旦它被分析,一次它没有被分析.
在Elasticsearch Reference中,请查看字符串排序和多字段指南,了解如何设置所需内容.
请注意,Elasticsearch 0.90.X和1.X之间的多字段映射配置已更改.根据您的版本使用适当的以下指南: