Use of the documented methods for distance calculation:
http://www.elasticsearch.org/guide/reference/modules/scripting.html
doc['field_name'].distance(lat, lon) The distance (in miles) of this
geo point field from the provided lat/lon.
doc['field_name'].distanceInKm(lat, lon) The distance (in km) of this
geo point field from the provided lat/lon.
You script looks good, can you provide a simple curl recreation? The distance methods were added from version 0.15.0.
On Wednesday, April 13, 2011 at 12:04 AM, Christopher Smith wrote:
Use of the documented methods for distance calculation:
Elasticsearch Platform — Find real-time answers at scale | Elastic
doc['field_name'].distance(lat, lon) The distance (in miles) of this
geo point field from the provided lat/lon.
doc['field_name'].distanceInKm(lat, lon) The distance (in km) of this
geo point field from the provided lat/lon.
And just for fun the log output:
[2011-04-12 14:42:12,280][DEBUG][action.search.type ] [War
Eagle] [rpl_edus][4], node[b1k0JkgsTleLjJYvA4VZvQ], [P], s[STARTED]:
Failed to execute
[org.elasticsearch.action.search.SearchRequest@2220f92c]
org.elasticsearch.search.query.QueryPhaseExecutionException: [rpl_edus]
[4]: query[custom score
(paused:F,function=org.elasticsearch.index.query.xcontent.CustomScoreQueryParser
$ScriptScoreFunction@58da27fe)],from[0],size[10]: Query Failed [Failed
to execute main query]
at
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)
at
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:
169)
at
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:
132)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:
76)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.access$000(TransportSearchTypeAction.java:75)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction$1.run(TransportSearchTypeAction.java:150)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: [Error: No field found for
[org.elasticsearch.index.field.data.doubles.DoubleDocFieldData@fc8eb26]]
[Near : {... (doc[amount].value/divisor)*we ....}]
^
[Line: 1, Column: 1]
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:
427)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:
140)
at
org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:
66)
at
org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:158)
at
org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:
115)
at
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:
116)
at
org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:
38)
at
org.elasticsearch.common.mvel2.ast.Substatement.getReducedValueAccelerated(Substatement.java:
42)
at
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:
116)
at
org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:
87)
at
org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:
125)
at org.elasticsearch.script.mvel.MvelScriptEngineService
$MvelSearchScript.run(MvelScriptEngineService.java:168)
at org.elasticsearch.script.mvel.MvelScriptEngineService
$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:172)
at
org.elasticsearch.index.query.xcontent.CustomScoreQueryParser
$ScriptScoreFunction.score(CustomScoreQueryParser.java:119)
at
org.elasticsearch.common.lucene.search.function.FunctionScoreQuery
$CustomBoostFactorScorer.score(FunctionScoreQuery.java:157)
at org.apache.lucene.search.FilteredQuery
$1$1.score(FilteredQuery.java:164)
at org.apache.lucene.search.TopScoreDocCollector
$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)
at org.apache.lucene.search.Scorer.score(Scorer.java:62)
at
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:212)
at
org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:
159)
at
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:170)
at org.apache.lucene.search.Searcher.search(Searcher.java:98)
at org.apache.lucene.search.Searcher.search(Searcher.java:108)
at
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:190)
... 9 more
Caused by: org.elasticsearch.ElasticSearchIllegalArgumentException: No
field found for
[org.elasticsearch.index.field.data.doubles.DoubleDocFieldData@fc8eb26]
at
org.elasticsearch.search.lookup.DocLookup.get(DocLookup.java:101)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getCollectionProperty(ReflectiveAccessorOptimizer.java:
708)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:
341)
... 32 more
Check Elasticsearch Platform — Find real-time answers at scale | Elastic. A curl recreation in this case will include the request that creates the index with the mapping, index data, and then executes the failed search request. And gist it.
On Wednesday, April 13, 2011 at 12:43 AM, Christopher Smith wrote:
And just for fun the log output:
[2011-04-12 14:42:12,280][DEBUG][action.search.type ] [War
Eagle] [rpl_edus][4], node[b1k0JkgsTleLjJYvA4VZvQ], [P], s[STARTED]:
Failed to execute
[org.elasticsearch.action.search.SearchRequest@2220f92c]
org.elasticsearch.search.query.QueryPhaseExecutionException: [rpl_edus]
[4]: query[custom score
(paused:F,function=org.elasticsearch.index.query.xcontent.CustomScoreQueryParser
$ScriptScoreFunction@58da27fe)],from[0],size[10]: Query Failed [Failed
to execute main query]
at
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)
at
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:
169)
at
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:
132)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:
76)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.access$000(TransportSearchTypeAction.java:75)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction$1.run(TransportSearchTypeAction.java:150)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: [Error: No field found for
[org.elasticsearch.index.field.data.doubles.DoubleDocFieldData@fc8eb26]]
[Near : {... (doc[amount].value/divisor)*we ....}]
^
[Line: 1, Column: 1]
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:
427)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:
140)
at
org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:
66)
at
org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:158)
at
org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:
115)
at
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:
116)
at
org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:
38)
at
org.elasticsearch.common.mvel2.ast.Substatement.getReducedValueAccelerated(Substatement.java:
42)
at
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:
116)
at
org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:
87)
at
org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:
125)
at org.elasticsearch.script.mvel.MvelScriptEngineService
$MvelSearchScript.run(MvelScriptEngineService.java:168)
at org.elasticsearch.script.mvel.MvelScriptEngineService
$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:172)
at
org.elasticsearch.index.query.xcontent.CustomScoreQueryParser
$ScriptScoreFunction.score(CustomScoreQueryParser.java:119)
at
org.elasticsearch.common.lucene.search.function.FunctionScoreQuery
$CustomBoostFactorScorer.score(FunctionScoreQuery.java:157)
at org.apache.lucene.search.FilteredQuery
$1$1.score(FilteredQuery.java:164)
at org.apache.lucene.search.TopScoreDocCollector
$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)
at org.apache.lucene.search.Scorer.score(Scorer.java:62)
at
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:212)
at
org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:
159)
at
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:170)
at org.apache.lucene.search.Searcher.search(Searcher.java:98)
at org.apache.lucene.search.Searcher.search(Searcher.java:108)
at
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:190)
... 9 more
Caused by: org.elasticsearch.ElasticSearchIllegalArgumentException: No
field found for
[org.elasticsearch.index.field.data.doubles.DoubleDocFieldData@fc8eb26]
at
org.elasticsearch.search.lookup.DocLookup.get(DocLookup.java:101)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getCollectionProperty(ReflectiveAccessorOptimizer.java:
708)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:
341)
... 32 more
And just for fun the log output:
[2011-04-12 14:46:47,894][DEBUG][action.search.type ] [War
Eagle] [edus][4], node[b1k0JkgsTleLjJYvA4VZvQ], [P], s[STARTED]:
Failed to execute
[org.elasticsearch.action.search.SearchRequest@7ab4753b]
org.elasticsearch.search.query.QueryPhaseExecutionException: [rpl_edus]
[4]: query[custom score
(paused:F,function=org.elasticsearch.index.query.xcontent.CustomScoreQueryParser
$ScriptScoreFunction@101853a4)],from[0],size[10]: Query Failed [Failed
to execute main query]
at
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)
at
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:
169)
at
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:
132)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:
76)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.access$000(TransportSearchTypeAction.java:75)
at
org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction$1.run(TransportSearchTypeAction.java:150)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: [Error: unable to resolve method:
org.elasticsearch.index.mapper.xcontent.geo.GeoPointDocFieldData.distance()
[arglength=0]]
[Near : {... _score * doc['location'].dista ....}]
^
[Line: 1, Column: 1]
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:
1006)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:
338)
at
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:
140)
at
org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:
66)
at
org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:158)
at
org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:
115)
at
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:
116)
at
org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:
87)
at
org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:
125)
at org.elasticsearch.script.mvel.MvelScriptEngineService
$MvelSearchScript.run(MvelScriptEngineService.java:168)
at org.elasticsearch.script.mvel.MvelScriptEngineService
$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:172)
at
org.elasticsearch.index.query.xcontent.CustomScoreQueryParser
$ScriptScoreFunction.score(CustomScoreQueryParser.java:119)
at
org.elasticsearch.common.lucene.search.function.FunctionScoreQuery
$CustomBoostFactorScorer.score(FunctionScoreQuery.java:157)
at org.apache.lucene.search.FilteredQuery
$1$1.score(FilteredQuery.java:164)
at org.apache.lucene.search.TopScoreDocCollector
$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)
at org.apache.lucene.search.Scorer.score(Scorer.java:62)
at
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:212)
at
org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:
159)
at
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:170)
at org.apache.lucene.search.Searcher.search(Searcher.java:98)
at org.apache.lucene.search.Searcher.search(Searcher.java:108)
at
org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:190)
... 9 more
BUT - in building this up I saw I didn't get the error. Thought maybe
it was due to my windows box so I tried with a new index against the
centos server - no error. Totally baffled - same installation -
different index.
The search SHOULD still work - I believe - but I was very confused as
to why my index throws up that error but a test index does not. The
only real difference is the real index is build up using the java api,
not curl, far as I am aware.
It also does not look like you use the same forumal. In terms of windows vs. centos, or Java API vs, REST API, there is no difference, REST API uses the Java API under the covers, and, at least for this case, does not seem like OS should make a difference.
Indeed, strange...
On Wednesday, April 13, 2011 at 1:30 AM, Christopher Smith wrote:
BUT - in building this up I saw I didn't get the error. Thought maybe
it was due to my windows box so I tried with a new index against the
centos server - no error. Totally baffled - same installation -
different index.
The search SHOULD still work - I believe - but I was very confused as
to why my index throws up that error but a test index does not. The
only real difference is the real index is build up using the java api,
not curl, far as I am aware.
Maybe try and create and index sample data the way you did with the original index? The API is not different elasticsearch wise, but, maybe the code you execute is different.
On Wednesday, April 13, 2011 at 2:49 AM, Christopher Smith wrote:
Do you have any suggestions on how I might go about further testing to
uncover the issue?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.