ElasticSearch search exception after migration 1.0.3 from 0.90.x

90 views Asked by At

We are migrating our ES cluster from 0.90 to 1.x (1.0.3), after following ES migration guides from

https://github.com/elasticsearch/elasticsearch/blob/2c777cef24603f2b7d79bd23c450dbc23927a24a/docs/reference/migration/migrate_1_0.asciidoc#search-request-source-filtering

Our app is a heavy-user of dynamic scripting (earlier accomplished with custom_score which is now changed to function_score) and uses boosting via script for search rankings. Though Tire doesn't support ES 1.x officially we are working on a fork to add 1.x fixes (https://github.com/dbose/retire/commit/1e90b159d645ec171c0e83b4e8301a432b72e246) before slowly moving to elasticsearch-ruby/rails client, which is now the officially library.

The problem is, our search works first time. But from next time onwards, ES crashes on the same query with following error

[2014-11-28 14:12:55,828][DEBUG][action.search.type       ] [Black Lama] [development-business][2], node[2yW9bVjbSLqyl3FkXXy_zw], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@31b8c5e3] lastShard [true]
org.elasticsearch.search.query.QueryPhaseExecutionException: [development-business][2]: query[filtered(function score (-company.exact: +(ops_status:new ops_status:active ops_status:claim_pending ops_status:claim_original ops_status:pending ops_status:paymentpending) +(customer_status:paymentpending customer_status:active customer_status:awaiting_payment customer_status:jumpstart) +domain_ids:[34834 TO 34834], functions: [{filter(*:*), function [script[relativeDistance = def(lat1, lon1, lat2, lon2) {
  if(lat1 == nil || lon1 == nil || lat2 == nil || lon2 == nil) {
    return 2147483647;
  }

  return Math.pow(lat2-lat1, 2) + Math.pow(lon2-lon1, 2);
};
closestPoint = def(lat, lon, output) {
  if(lat == nil || lon == nil) {
    return (output == 'object' ? _source.locations[0] : _score);
  }

  closest = 2147483647;
  closest_location = _source.locations[0];
  for(loc : _source.locations) {
    d = relativeDistance(loc.geo_point.lat, loc.geo_point.lon, lat, lon);
    if(closest > d) { closest = d; closest_location = loc; }
  };

  return (output == 'object' ? closest_location : closest);
};
coverageScore = def(region_id, region_type, region_ancestors) {
  weights = [60000, 50000, 40000, 30000, 20000, 10000];
  weight_index = 0;
  if(region_type == "suburb") { region_type = "location" }

  // find the region or its subregions
  types = ["national", "state", "region", "area", "location", "suburb"];
  active = false;
  for(type: types) {
    if(active || region_type == type){
      active = true;
      items = (type != "location" ? _source.serviced_areas : _source.locations);
      for(item: items) {
        if((type == "location" || item.region_type == type) && item[region_type] == region_id) {
          return weights[weight_index];
        }
      }
      weight_index += 1;
    }
  }

  // now expand to larger regions
  ancestor_index = 0;
  active = false;
  reversed_types = ["suburb", "location", "area", "region", "state", "national"];
  for(type: reversed_types) {
    if(active) {
      items = (type != "location" ? _source.serviced_areas : _source.locations);
      for(item: items) {
        if((type == "location" || item.region_type == type) && item.id == region_ancestors[ancestor_index]) {
          return weights[weight_index];
        }
      }
      ancestor_index += 1;
      weight_index += 1;
    }
    else if(region_type == type) {
      active = true;
    }
  }

  // didn't match anything
  return 0;
};
matchKeyword = def(keyword, keywords_weightings) {
  for(kw: keywords_weightings) {
    if(kw.keyword == keyword) {
      return kw.weighting;
    }
  }
  return 0.0;
};
categoryKeywordWeightingScore = def(keywords) {
  //for(keyword: keywords) {
  //  score_to_add += matchKeyword(keyword, _source.category_keywords);
  //}
  for(kw: _source.category_keywords) {
    if(kw.keyword == keywords) {
      return kw.weighting;
    }
  }
  return 0.0; // TODO: normalise this
};
primaryCategoryScore = def(category_id) {
  for(id : _source.category_ids) {
    if(id == category_id) {
      return 10000;
    }
  }
  return 0;
};
score = _score;

// CATEGORY + KEYWORD SCORING

primary_category_bonus = primaryCategoryScore(category_id);
score += primary_category_bonus;

if(primary_category_bonus == 0) {
  score += categoryKeywordWeightingScore(keywords);
}

// FEATURED BUSINESSES SCORING

for(featured : _source.featured_businesses) {
  if (featured.domain_id == domain_id && featured.category_id == category_id) {
    score += 10000000 * (1 + featured.level);
  }
}

// BUSINESS TIER SCORING

score += _source.plan_ranking * 100000;

// LOCATION SCORING

if (_source.locations != null) {

  if (_source.serviced_areas != null) {
    // score by coverage areas (locations + serviced areas)
    score += coverageScore(region_id, region_type, region_ancestors);
  }

  // score by distance
  point = closestPoint(lat, lon, 'object');
  if (point.id != region_id) {
    score += (10.0/(relativeDistance(point.geo_point.lat, point.geo_point.lon, lat, lon) + 0.001));
  }
}

// CONTENT SCORING

if (_source.company_lower == keywords) {
  score += 750000;
}

if (_source.primary_domain_id == domain_id) {
  score += 100;
}

if (_source.phone_number != null && _source.phone_number != "") {
  score += 50;
}

if (_source.star_rating != null && _source.star_rating > 0) {
  score += _source.star_rating * 50;
}

return score;
], params [{primaryCategoryScore=org.elasticsearch.common.mvel2.ast.PrototypalFunctionInstance@7bf90a55, _source=org.elasticsearch.search.lookup.SourceLookup@97a8b43, matchKeyword=org.elasticsearch.common.mvel2.ast.PrototypalFunctionInstance@4c4ce091, region_ancestors=[0], score=0.12918511, region_id=2, _score=0.12918511, coverageScore=org.elasticsearch.common.mvel2.ast.PrototypalFunctionInstance@46750a05, categoryKeywordWeightingScore=org.elasticsearch.common.mvel2.ast.PrototypalFunctionInstance@2de4f266, region_name=nsw, _FREQUENCIES=8, _fields=org.elasticsearch.search.lookup.FieldsLookup@11e61e14, lat=0.0, region_type=state, _PAYLOADS=4, lon=0.0, keywords=, domain_id=34834, _index=org.elasticsearch.search.lookup.IndexLookup@1ac0bc3a, category_id=null, closestPoint=org.elasticsearch.common.mvel2.ast.PrototypalFunctionInstance@6385918e, _doc=org.elasticsearch.search.lookup.DocLookup@561734ad, doc=org.elasticsearch.search.lookup.DocLookup@561734ad, relativeDistance=org.elasticsearch.common.mvel2.ast.PrototypalFunctionInstance@d837603, _CACHE=32, _OFFSETS=2, _POSITIONS=16}]]}]))->cache(_type:business)],from[0],size[20]: Query Failed [Failed to execute main query]
 at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:126)
 at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:249)
 at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)
 at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
 at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)
 at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203)
 at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
 at java.lang.Thread.run(Thread.java:680)

Any clues to debug this would be fantastic ! Thanks guys

0

There are 0 answers