[英]Multiple elasticsearch filters
我正在使用Tire for rails集成elasticsearch。 這有點令人困惑,我想確保自己做得對。
這是我應用多個過濾器的方式嗎? 我基本上是想檢查'mixtape_id IS NULL AND artist_id IS NOT NULL'
def self.search(query)
tire.search() do
query { string query }
filter :exists, { field: 'artist_id' }
filter :not, { exists: { field: 'mixtape_id' } }
end
end
這是我的第二次嘗試,看來還是沒用
def self.search(query)
tire.search(load: true) do
query { string query }
filter :and, [
{ exists: { field: 'artist_id' } },
{ not: { exists: { field: 'mixtape_id' } } }
]
end
end
謝謝
我大部分時間都在工作,但我每次都嘆了口氣卻愚蠢地忘記了每次都要強制重新索引。 這是一些利用missing
過濾器的清理代碼。
def self.search(query)
tire.search load: { include: { artist: :attachments } } do
query { string query }
filter :and, [
{ exists: { field: 'artist_id' } },
{ missing: { field: 'mixtape_id' } }
]
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.