【发布时间】:2016-05-10 20:58:33
【问题描述】:
我实际上可以用这个来执行一个简单的匹配搜索:
query: {match: {searchable: {query:search}}}
这很好,我的可搜索字段在我的映射中进行了分析。
现在我想对多个字段执行搜索:1 个字符串,其他都是数字。
我的映射:
mappings dynamic: 'false' do
indexes :searchable, analyzer: "custom_index_analyzer", search_analyzer: "custom_search_analyzer"
indexes :year, type: "integer"
indexes :country_id, type: "integer"
indexes :region_id, type: "integer"
indexes :appellation_id, type: "integer"
indexes :category_id, type: "integer"
end
def as_indexed_json(options={})
as_json(
only: [:searchable, :year, :country_id, :region_id, :appellation_id, :category_id]
)
end
我试过这个:
query: {
filtered: {
query: {
match: {
searchable: search
}
},
filter: {
term: {
country_id: "1"
},
term: {
region_id: "2"
},
term: {
appellation_id: "34"
}
}
}
},
sort: {
_score: {
order: :desc
},
year: {
order: :desc,
ignore_unmapped: true
}
},
size:100
它运行良好,但它会在所有情况下给我 100 个结果,从发送的 appellation_id (34),即使可搜索字段离文本搜索很远。
我也尝试过 BOOL 查询:
self.search(query: {
bool: {
must: [
{
match: {
country_id: "1"
},
match: {
region_id: "2"
},
match: {
appellation_id: "34"
},
match: {
searchable: search
}
}
]
}
},
sort: {
_score: {
order: :desc
},
year: {
order: :desc,
ignore_unmapped: true
}
},
size:100
)
但它会给我所有与可搜索字段匹配的结果,并且不关心想要的 appellation_id。
我的目标是获得最好的结果和性能,并要求 ES 给我来自 country_id=X、region_id=Y、appellation_id=Z 的所有数据,最后对这组结果与可搜索字段进行匹配...并且不要通过可搜索的文本获得与现实相去甚远的结果。
谢谢。
【问题讨论】:
标签: elasticsearch field match