我尝试按照elasticsearch文档使用过滤器执行弹性搜索但不能这样做。 这是我的例子:
class Post
def as_indexed_json(options={})
self.as_json(
only: [ :id, :title, :published ],
filter: {
bool: {
should: {
term: { published: true }
}
}
}
)
end
end
你们之前尝过这个吗? 有人能帮我一把吗?
干杯
答案 0 :(得分:0)
不太确定,但在我看来,你有一个ES语法错误。
你能否通过ES请求发送给JSon?
我猜你的JSon应该是这样的:
{
"filter": {
"bool": {
"should": [
{
"term": {
"published": true
}
}
]
}
}
}
但是你发送了这个:
{
"only" : [ "valueForId", "valueForTitle", "isPublished" ],
"filter": {
"bool": {
"should": [
{
"term": {
"published": true
}
}
]
}
}
}
注意:有关ES的更准确答案,请告知您正在使用的工具版本(例如ES 1.0.1)和发送到ES服务器的数据(JSon的内容),因为ES有一个相当的过去几个月里重要的语法变化,有时很难弄清楚你的班级正在做什么或你的参数中有什么(:id,:title ...)。