1

I've been putting together a complex query for our app in elasticsearch, and finally got it all working...except I am getting duplicates in my results. Can't live with that, so I found this solution: Remove duplicate documents from a search in Elasticsearch

Unfortunately, I'm having trouble getting the syntax right for adding this aggs thing to my query hash.

I've got this so far:

 aggs = {
  aggs: {
    dedup: {
      terms: {
        field: "urn"
      },
      aggs: {
        dedup_docs: {
          top_hits: {
            size: 1
          }
        }
      }    
    }
  }
}

query_hash[:aggs] = aggs

and I'm getting this error back from elastic: Parse Failure [Could not find aggregator type [dedup] in [aggs]]

I logged the final form of my complex query hash and it looks like this: {:query=>{:filtered=>{:query=>{:function_score=>{:query=>{:query_string=>{:query=>"red*", :fields=>["title", "short_description", "long_description"], :default_operator=>"OR"}}, :functions=>[{:field_value_factor=>{:field=>"recent_donation_frequency", :factor=>1.1}}, {:field_value_factor=>{:field=>"total_donations_amount_cents", :factor=>100.0}}, {:field_value_factor=>{:field=>"creation_recency", :factor=>1.2}}, {:field_value_factor=>{:field=>"ending_soonishness", :factor=>1.0}}], :score_mode=>"sum"}}, :filter=>{:bool=>{:must=>[{:term=>{:published=>true}}, {:terms=>{:_type=>["org", "widget", "campaign", "individual"]}}], :should=>[], :must_not=>[]}}}}, :aggs=>{:aggs=>{:dedup=>{:terms=>{:field=>"urn"}, :aggs=>{:dedup_docs=>{:top_hits=>{:size=>1}}}}}}}

thanks!

Community
  • 1
  • 1
Jeff
  • 11
  • 1

0 Answers0