Last active
August 29, 2015 14:05
-
-
Save pmusa/ef9a02210d736ee020d9 to your computer and use it in GitHub Desktop.
Elasticsearch Function Score does not work with fields of object type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE test | |
POST test | |
{ | |
"settings": { | |
"number_of_shards": 1, | |
"index": { | |
"number_of_replicas": "0" | |
} | |
}, | |
"mappings": { | |
"tst": { | |
"properties": { | |
"name": { | |
"type": "string" | |
}, | |
"fsot": { | |
"type": "object", | |
"properties": { | |
"testobj": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
POST test/tst/1 | |
{ | |
"name": "t1", | |
"fsot": [ | |
{ | |
"testobj": "test1" | |
}, | |
{ | |
"testobj": "test2" | |
} | |
] | |
} | |
GET test/tst/_search | |
GET test/tst/_mapping | |
POST test/tst/_search | |
{ | |
"query": { | |
"function_score": { | |
"boost_mode": "replace", | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"exists": { | |
"field": "fsot" | |
} | |
} | |
} | |
}, | |
"functions": [ | |
{ | |
"script_score": { | |
"script": "if ( doc.get('name') == null ) 0; else 1;" | |
} | |
} | |
] | |
} | |
} | |
} | |
POST test/tst/_search | |
{ | |
"query": { | |
"function_score": { | |
"boost_mode": "replace", | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"exists": { | |
"field": "fsot" | |
} | |
} | |
} | |
}, | |
"functions": [ | |
{ | |
"script_score": { | |
"script": "if ( doc.get('fsot') == null ) 0; else 1;" | |
} | |
} | |
] | |
} | |
} | |
} | |
{ | |
"error": "SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[nhZxfl9HQOqWPEhSluWnGg][test][0]: QueryPhaseExecutionException[[test][0]: query[filtered(function score (ConstantScore(cache(BooleanFilter(_field_names:fsot.testobj))), functions: [{filter(*:*), function [script[if ( doc.get('fsot') == null ) 0; else 1;], params [null]]}]))->cache(_type:tst)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: PropertyAccessException[[Error: doc.get('fsot'): No field found for [fsot] in mapping with types [tst]]\n[Near : {... if ( doc.get('fsot') == null ) ....}]\n ^\n[Line: 1, Column: 1]]; nested: InvocationTargetException; nested: ElasticsearchIllegalArgumentException[No field found for [fsot] in mapping with types [tst]]; }]", | |
"status": 500 | |
} | |
[2014-08-24 22:55:58,510][DEBUG][action.search.type ] [Gabe Jones] [test][0], node[nhZxfl9HQOqWPEhSluWnGg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@6661b3ef] | |
org.elasticsearch.search.query.QueryPhaseExecutionException: [test][0]: query[filtered(function score (ConstantScore(cache(BooleanFilter(_field_names:fsot.testobj))), functions: [{filter(*:*), function [script[if ( doc.get('fsot') == null ) 0; else 1;], params [null]]}]))->cache(_type:tst)],from[0],size[10]: Query Failed [Failed to execute main query] | |
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:162) | |
at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:334) | |
at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:308) | |
at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:305) | |
at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:517) | |
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: [Error: doc.get('fsot'): No field found for [fsot] in mapping with types [tst]] | |
[Near : {... if ( doc.get('fsot') == null ) ....}] | |
^ | |
[Line: 1, Column: 1] | |
at org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:413) | |
at org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:140) | |
at org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:68) | |
at org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:159) | |
at org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115) | |
at org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:114) | |
at org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38) | |
at org.elasticsearch.common.mvel2.ast.IfNode.getReducedValueAccelerated(IfNode.java:73) | |
at org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:86) | |
at org.elasticsearch.common.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123) | |
at org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119) | |
at org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113) | |
at org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.run(MvelScriptEngineService.java:196) | |
at org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.runAsDouble(MvelScriptEngineService.java:211) | |
at org.elasticsearch.common.lucene.search.function.ScriptScoreFunction.score(ScriptScoreFunction.java:54) | |
at org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery$CustomBoostFactorScorer.score(FiltersFunctionScoreQuery.java:320) | |
at org.apache.lucene.search.TopScoreDocCollector$OutOfOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:140) | |
at org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:193) | |
at org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:163) | |
at org.apache.lucene.search.BulkScorer.score(BulkScorer.java:35) | |
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:621) | |
at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:175) | |
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491) | |
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448) | |
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281) | |
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269) | |
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:156) | |
... 7 more | |
Caused by: java.lang.reflect.InvocationTargetException | |
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:606) | |
at org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1097) | |
at org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:980) | |
at org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:340) | |
... 33 more | |
Caused by: org.elasticsearch.ElasticsearchIllegalArgumentException: No field found for [fsot] in mapping with types [tst] | |
at org.elasticsearch.search.lookup.DocLookup.get(DocLookup.java:103) | |
... 39 more | |
[2014-08-24 22:55:58,511][DEBUG][action.search.type ] [Gabe Jones] All shards failed for phase: [query_fetch] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment