你好,我正在尝试使用ElasticSearch引擎按距离对实体进行排序。我添加了5个具有“GeoPoint”值的实体,现在我尝试按距离排序返回它。
我的模型类
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "location")
public class Location implements Serializable {
private static final long serialVersionUID = -8120158607063175447L;
@Field
@Id
private Long id;
@Field
private String title;
@GeoPointField
private GeoPoint location;
}
我的示例测试代码
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withSort(new GeoDistanceSortBuilder("location").point(52.1,13.2))
.build();
Page<Location> places = elasticsearchTemplate.queryForPage(searchQuery, Location.class);
堆栈跟踪
Feb 18, 2017 12:25:33 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Invocation of init method failed; nested exception is Failed to execute phase [dfs], all shards failed; shardFailures {[I-X8ZtXlQ1OTOkozNrmpWA][location][0]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][1]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][2]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][3]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][4]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:540)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: Failed to execute phase [dfs], all shards failed; shardFailures {[I-X8ZtXlQ1OTOkozNrmpWA][location][0]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][1]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][2]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][3]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }{[I-X8ZtXlQ1OTOkozNrmpWA][location][4]: RemoteTransportException[[Stinger][172.17.0.4:9300][indices:data/read/search[phase/dfs]]]; nested: SearchParseException[failed to parse search source [{"from":0,"size":10,"sort":[{"_geo_distance":{"location":[{"lat":53.2,"lon":13.2}]}}]}]]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort]; }
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:228)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:174)
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.processException(TransportService.java:821)
at org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:799)
at org.elasticsearch.transport.TransportService$4.onFailure(TransportService.java:361)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:39)
... 3 more
Caused by: NotSerializableExceptionWrapper[failed to find mapper for [location] for geo distance based sort]; nested: IllegalArgumentException[failed to find mapper for [location] for geo distance based sort];
at org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:386)
at org.elasticsearch.action.search.SearchPhaseExecutionException.guessRootCauses(SearchPhaseExecutionException.java:152)
at org.elasticsearch.action.search.SearchPhaseExecutionException.getCause(SearchPhaseExecutionException.java:99)
at org.elasticsearch.ElasticsearchException.writeTo(ElasticsearchException.java:226)
at org.elasticsearch.action.search.SearchPhaseExecutionException.writeTo(SearchPhaseExecutionException.java:64)
at org.elasticsearch.common.io.stream.StreamOutput.writeThrowable(StreamOutput.java:560)
at org.elasticsearch.ElasticsearchException.writeTo(ElasticsearchException.java:226)
at org.elasticsearch.transport.ActionTransportException.writeTo(ActionTransportException.java:64)
at org.elasticsearch.common.io.stream.StreamOutput.writeThrowable(StreamOutput.java:560)
at org.elasticsearch.transport.netty.NettyTransportChannel.sendResponse(NettyTransportChannel.java:120)
at org.elasticsearch.action.support.HandledTransportAction$TransportHandler$1.onFailure(HandledTransportAction.java:58)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.raiseEarlyFailure(TransportSearchTypeAction.java:316)
... 10 more
Caused by: java.lang.IllegalArgumentException: failed to find mapper for [location] for geo distance based sort
at org.elasticsearch.search.sort.GeoDistanceSortParser.parse(GeoDistanceSortParser.java:161)
at org.elasticsearch.search.sort.SortParseElement.addCompoundSortField(SortParseElement.java:141)
at org.elasticsearch.search.sort.SortParseElement.parse(SortParseElement.java:84)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:836)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:652)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:618)
at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:263)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:350)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
... 3 more
Feb 18, 2017 12:25:33 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet threw load() exception
java.lang.IllegalArgumentException: failed to find mapper for [location] for geo distance based sort
at org.elasticsearch.search.sort.GeoDistanceSortParser.parse(GeoDistanceSortParser.java:161)
at org.elasticsearch.search.sort.SortParseElement.addCompoundSortField(SortParseElement.java:141)
at org.elasticsearch.search.sort.SortParseElement.parse(SortParseElement.java:84)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:836)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:652)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:618)
at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:263)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:350)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我从Spring数据弹性搜索中排除了一些Jackson项目
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<exclusions>
<exclusion>
<artifactId>com.google</artifactId>
<groupId>guava</groupId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-smile</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
</exclusion>
</exclusions>
</dependency>
ES节点中生成的映射
curl -XGET 'http://localhost:9200/location/_mapping?pretty'
{
"location" : {
"mappings" : {
"location" : {
"properties" : {
"id" : {
"type" : "long"
},
"location" : {
"properties" : {
"geohash" : {
"type" : "string"
},
"lat" : {
"type" : "double"
},
"lon" : {
"type" : "double"
}
}
},
"title" : {
"type" : "string"
}
}
}
}
}
}
已使用导入组织。springframework。数据elasticsearch。果心地理位置。地质点 改为导入组织。elasticsearch。常见的地理位置。地质点
**麦克风下降**
相关错误是未能找到[位置]的基于地理距离的排序映射器]
,这表明位置
字段没有地理点所需的正确映射。您需要将位置字段的映射更新为地理点类型:
PUT <host_url>:<port>/location/mapping/<type_name>
{
"<type_name>" : {
"properties" : {
"location": {
"type": "geo_point"
}
}
}
}
如果位置字段中已有数据,则需要使用正确的映射重新创建索引,并重新索引所有数据。
我有一个用于使用elasticsearch GeopointSpring引导应用程序。当我保存弹性索引并创建geoDistanceQuery时,我得到了QueryShardException[未能找到geo_point字段[customer]]异常。 我的文件; 储存库; 保存和获取方法;
我正在利用spring elasticsearch数据创建文档、索引以及执行与查询相关的操作。根据spring elasticsearch数据指定的文档,我使用了最新的spring-data-elasticsearch=4.1.0-snapshot和弹性restclient和transport client版本=7.6.2。但我得到了下面提到的错误 我查看了docs-https://docs.sp
我使用的是Spring Boot MVC,Spring的在数据源配置之前被调用,数据源配置加载到中。 总是首先被调用,因此从来没有为Autowed定义过bean。 我尝试了从到的所有方法。我找不到一个像样的解释。但是我需要在数据源运行WebSecurity之前为它创建一个Bean
问题内容: 我正在尝试传递给jasper报告字符串位置的模板。因此,我在模板和值中传递了参数的键。当我在项目中有图像时,一切都在工作,但我想在另一个地方使用它。有什么方法可以从例如属性文件中读取参数?我不知道为什么这种解决方案不起作用: 我的形象: … 错误: 问题答案: 好的,我找到了…应该是:
问题内容: 我尝试基于使用Hibernate内存数据库配置Spring Data : 但是我一遍又一遍地得到: org.hibernate.cfg.Environment。HHH000206:找不到hibernate.properties 问题是我不想在文件中指定它,就像我以前没有Spring Data一样,我想在配置中设置它,就像我基于的答案一样。我想念什么吗?预先感谢您的帮助。 问题答案: 那
Spring boot版本1.5.3