2013-08-09 2 views
0

tire gem을 사용하여 Rails 애플리케이션에서 탄성 검색에 액세스합니다. 내가 전혀 생각이 왜이 없다타이어/탄성 검색 : 정렬 작동하지 않음

def Tweet.search_tweets(params = {}) 
Tweet.search(page: params[:page], per_page: params[:per_page]) do 

    if params[:query_string].present? || params[:sentiment].present? || 
    (params[:start_date].present? && params[:end_date].present?) 
    query do 
     boolean do 
     if params[:query_string].present? 
      must { string params[:query_string], default_operator: "AND" } 
     end 

     if params[:sentiment].present? 
      must { term :sentiment, params[:sentiment]} 
     end 

     if params[:start_date].present? && params[:end_date].present? 
      must { string "created_at:[#{params[:start_date]} TO #{params[:end_date]}]"} 
     end 
     end 
    end 
    else 
    query do 
     all 
    end 
    end 

    if params[:entity_id].present? 
    filter :terms, entities_ids: [params[:entity_id]] 
    end 

    if params[:sort].present? 
    sort { by params[:sort][:by], params[:sort][:order] } 
    end 

end 

:

[2013-08-09 15:06:08,538][DEBUG][action.search.type  ] [Nitro] [tweets][3], node[INKC2ryGQ4Sx1qYP4qC-Og], [P], s[STARTED]: Failed to execute [[email protected]] 
org.elasticsearch.search.SearchParseException: [tweets][3]: query[ConstantScore(*:*)],from[-1],size[-1]: Parse Failure [Failed to parse source [{ 
    "query": { 
    "match_all": { 

    } 
    }, 
    "sort": [ 
    { 
     "author": "asc" 
    } 
    ], 
    "filter": { 
    "terms": { 
     "entities_ids": [ 
     "10" 
     ] 
    } 
    }, 
    "size": 10, 
    "from": 0 
}]] 

는이처럼 보이는 방법 생성 : 내 코드는 docs for sort에 대한 이해에 올바른 다음 쿼리를 생성 이 작동하지 않습니다.

답변

1

정렬과 비슷한 문제가 있습니다 ... 해당 필드를 인덱싱 한 방법에 따라 다릅니다. 그것의 토큰 화 된 문자열이 있다면 당신은 고생 할 수 있습니다. 대신 당신은 multifield를 사용하지 그것을 분석하거나 _source에 따라 _script 종류의 사용할 수있는 수 : 조금 도움이

{ "query": { 
    "query_string": { 
     "query": "something or other" 
    } }, "sort": { 
    "_script": { 
     "script": "_source.contentLegend", 
     "type": "string", 
     "order": "desc" 
    } } } 

희망을!

관련 문제