Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure in saving percolate query with date type function score #6340

Closed
ajhalani opened this issue May 29, 2014 · 5 comments
Closed

Failure in saving percolate query with date type function score #6340

ajhalani opened this issue May 29, 2014 · 5 comments
Assignees
Labels
>bug help wanted adoptme :Search/Percolator Reverse search: find queries that match a document

Comments

@ajhalani
Copy link

When I try to save a query in percolate which has function score on a date field, it fails with error Failed to parse NullPointerException. If function score is on another data type field like number, it works fine.

PUT testindex

PUT testindex/document/1
{
  "actionDate" : "2014-05-01",
  "score" : 5
}

PUT testindex/.percolator/1
{
  "query" : {
    "function_score" : {
      "functions" : [
        {
          "exp" :{ 
              "actionDate" : {
                "origin" : "now",
                "scale" : "10d"
              }
          }
        }
      ],
      "query" : {
        "match_all": {}
      }
    }
  }
}

{
   "error": "RemoteTransportException[[nylxdev1.node][inet[/172.17.9.175:9301]][index]]; nested: PercolatorException[[testindex] failed to parse query [1]]; nested: QueryParsingException[[testindex] Failed to parse]; nested: NullPointerException; ",
   "status": 500
}
@martijnvg martijnvg self-assigned this May 30, 2014
@martijnvg
Copy link
Member

Thanks for reporting this @ajhalani!

Stacktrace:

org.elasticsearch.index.percolator.PercolatorException: [testindex] failed to parse query [1]
    at org.elasticsearch.index.percolator.PercolatorQueriesRegistry.parsePercolatorDocument(PercolatorQueriesRegistry.java:182)
    at org.elasticsearch.index.percolator.PercolatorQueriesRegistry$RealTimePercolatorOperationListener.preIndex(PercolatorQueriesRegistry.java:306)
    at org.elasticsearch.index.indexing.ShardIndexingService.preIndex(ShardIndexingService.java:132)
    at org.elasticsearch.index.shard.service.InternalIndexShard.index(InternalIndexShard.java:401)
    at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:198)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:534)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:433)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.index.query.QueryParsingException: [testindex] Failed to parse
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:234)
    at org.elasticsearch.index.percolator.PercolatorQueriesRegistry.parseQuery(PercolatorQueriesRegistry.java:195)
    at org.elasticsearch.index.percolator.PercolatorQueriesRegistry.parsePercolatorDocument(PercolatorQueriesRegistry.java:180)
    ... 9 more
Caused by: java.lang.NullPointerException
    at org.elasticsearch.index.query.functionscore.DecayFunctionParser.parseDateVariable(DecayFunctionParser.java:268)
    at org.elasticsearch.index.query.functionscore.DecayFunctionParser.parseVariable(DecayFunctionParser.java:166)
    at org.elasticsearch.index.query.functionscore.DecayFunctionParser.parse(DecayFunctionParser.java:148)
    at org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser.parseFiltersAndFunctions(FunctionScoreQueryParser.java:190)
    at org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser.parse(FunctionScoreQueryParser.java:116)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:227)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:334)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:230)
    ... 11 more

The search context isn't set during parsing of the percolator query, causing the above stacktrace.

@s1monw s1monw added v1.2.2 and removed v1.2.1 labels Jun 3, 2014
@clintongormley clintongormley added v1.5.0 :Search/Percolator Reverse search: find queries that match a document labels Dec 30, 2014
@martijnvg
Copy link
Member

Fixing the NPE that is occurring is relatively easy, but there is a bigger problem with this percolator query.

The now usage in this function score function is problematic, because it is resolved at percolate query register time and after that for each percolate request the now time will stay the same. This is similar to date ranges issue in percolator queries and alias filters, which was fixed only recently: #8534

Fixing this will add additional logic similar as was added via #8534, do we want this extra complexity?

@clintongormley
Copy link

@martijnvg i think so - it makes sense for the same reasons as #8534

@s1monw s1monw added v1.6.0 and removed v1.5.0 labels Mar 17, 2015
@clintongormley clintongormley added help wanted adoptme and removed discuss labels Oct 14, 2015
@clintongormley
Copy link

With the new query parsing coming in 3.0, it should be possible to handle dates correctly.

@martijnvg there's nothing to do before 3.0, is there?

@martijnvg
Copy link
Member

This has been fixed some time ago, I think I just forgot to close this issue:
7cc2bc8

If now is used in range queries we resolve that at lucene query rewrite time. In case of the percolator that happens at percolate time and the current time should therefor not be stale any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug help wanted adoptme :Search/Percolator Reverse search: find queries that match a document
Projects
None yet
Development

No branches or pull requests

4 participants