我在我的rails app中有这个查询:
query = { query: { bool: { must: [], minimum_should_match:"75%" }}, sort: { _score: { order: :desc }, year: { order: :desc, ignore_unmapped: true }} }
query[:query][:bool][:must] << { match: { winery: @winery.name }} # use winery field, not searchable
query[:query][:bool][:must] << { term: { country_id: @winery.country_id }} if !@winery.country_id.nil?
query[:query][:bool][:must] << { term: { region_id: @winery.region_id }} if !@winery.region_id.nil?
@results = Wine.search(query)
事实上,我们不知道在哪里放置 minimum_should_match 选项。只有在必须之后才允许。问题是我可以改变75%的值,我的结果没有任何变化。
我的目标是仅将其用于 match:{winery:@ winery.name} 字段。
-
例如,我目前正在搜索 Quinta da Romaneira 作为@ winery.name。
我得到了:
结果。
所以我希望查询只返回第一个,第二个ngrams距离太长。
使用像这样的更经典的查询:
self.search(query: {match: {winery: {query:search, minimum_should_match:"75%"}}})
minimum_should_match 工作正常。
那么如何更改我的第一个查询以便minimum_should_match可以对结果产生影响?
我的映射是在@ winery.name字段中使用ngrams:
settings index: { number_of_shards: 1, number_of_replicas: 1 }, analysis: {
analyzer: {
custom_index_analyzer: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase", "asciifolding", "custom_word_delimiter", "custom_fr_stopwords", "custom_en_stopwords", "custom_de_stopwords", "custom_es_stopwords", "custom_it_stopwords", "custom_pt_stopwords", "custom_unique_token", "custom_tokenizer"]
},
custom_search_analyzer: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase", "asciifolding", "custom_word_delimiter", "custom_fr_stopwords", "custom_en_stopwords", "custom_de_stopwords", "custom_es_stopwords", "custom_it_stopwords", "custom_pt_stopwords", "custom_unique_token", "custom_tokenizer"]
}
},
filter: {
custom_word_delimiter: {
type: "word_delimiter"
},
custom_unique_token: {
type: "unique",
only_on_same_position: "false"
},
custom_tokenizer: {
type: "nGram",
min_gram: "3",
max_gram: "8",
token_chars: [ "letter", "digit" ]
}
}
} do
mappings dynamic: 'false' do
indexes :winery, analyzer: "custom_index_analyzer", search_analyzer: "custom_search_analyzer"
indexes :name, analyzer: "custom_index_analyzer", search_analyzer: "custom_search_analyzer"
indexes :country_id, type: "integer"
indexes :region_id, type: "integer"
end
end
感谢。