我基本上想做一个搜索:
select all from index_name where tag = 'big data' and city = 'tokyo'
代码是:
require "elasticsearch"
client = Elasticsearch::Client.new log: true
client.search index: 'candidates', body:
{
query: {
match: {
tags: search_term
}
}
}
效果很好。但是,当我更改为:
match: {
tags: search_term, city: 'Tokyo'
}
也就是说,只要添加另一个参数,我就会收到错误。
我尝试添加
filter: {
city: 'Tokyo'
}
也没有成功。
谢谢大家,最好的方法是什么?
最佳答案
您需要检查Elasticsearch query DSL 。对于简单的“A 和 B”查询,您只需使用 bool / must
query 。用这个替换你的 body :
client.search index: 'candidates', body:
{
query: {
bool: {
must: [
{
match: {
tags: 'big data'
}
},
{
match: {
city: 'tokyo'
}
}
]
}
}
}
关于ruby - 使用 ruby elasticsearch gem,如何使用多个参数进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30678135/