제목으로 검색하고 레코드 유형이 제공되면 쿼리에 추가하는 논리가있는 elasticsearch 쿼리를 만들려고합니다. 저는 이것을 했어요
def to_es_query
{
query: {
match: {
title_en: { query: @title }
}.merge!(optional_params)
}
}
end
def optional_params
type_param
end
def type_param
return {} unless @type
{
match: {
type: {
query: @type
}
}
}
end
내가 뭘 잘못하고 있니?
UPDATE (이전 답변이 잘못 되었기 때문에 제거됨)
탄력적 검색에 대해 조금 읽은 후 이것이 당신에게 효과적이라고 생각합니다.
def to_es_query
{ query: { bool: { must: musts } } }
end
def musts
@musts ||= [{ match:{ title_en: @title } }]
#possibly { term: {type: @type } } } would work for an exact search
# e.g. type = 'serie'
@musts << { match: { type: @type } } if @type
@musts
end
그러면 모든 기준이 참이어야하는 부울 검색이 생성됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다