IndexMissingException:[News]缺失

时间:2016-12-09 15:49:32

标签: postgresql elasticsearch spring-boot spring-data

我在Spring启动时使用了弹性搜索。我将数据保存到postgres中的主数据库,并在elasticsearch(ES)中进行搜索。我已经配置了添加一些数据。我可以看到弹性搜索和postgres中都有我的数据。但是当我尝试通过searchQuery运行自定义查询时返回我的错误:

2016-12-09 20:03:09.586 ERROR 1704 --- [pool-2-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task.

org.elasticsearch.indices.IndexMissingException: [provenNews] missing
    at org.elasticsearch.cluster.metadata.MetaData.convertFromWildcards(MetaData.java:868)
    at org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:685)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.<init>(TransportSearchTypeAction.java:113)
    at org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.<init>(TransportSearchDfsQueryThenFetchAction.java:75)
    at org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction$AsyncAction.<init>(TransportSearchDfsQueryThenFetchAction.java:68)
    at org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction.doExecute(TransportSearchDfsQueryThenFetchAction.java:65)
    at org.elasticsearch.action.search.type.TransportSearchDfsQueryThenFetchAction.doExecute(TransportSearchDfsQueryThenFetchAction.java:55)
    at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:75)

这是我的代码: 配置类

@Configuration
@EnableTransactionManagement
@EnableElasticsearchRepositories(basePackages = "org.news.proven.repository")
public class ProjectConfiguration {

    @Bean
    public HibernateJpaSessionFactoryBean sessionFactory() {
        return new HibernateJpaSessionFactoryBean();
    }

    @Bean
    public ElasticsearchTemplate elasticsearchTemplate() {
        return new ElasticsearchTemplate(getNodeClient());
    }


    private static NodeClient getNodeClient() {
        return (NodeClient) nodeBuilder().clusterName(UUID.randomUUID().toString()).local(true).node()
                .client();
    }

}

我的类调用searchQuery

@Service
public class NewsSearchServiceBean implements NewsSearchService {

    @Autowired
    private ProvenNewsRepository newsSearchRepository;

    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;

    public Page<ProvenNews> search(String query, int page)
    {
    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery(query)
            .field("title", 0.6f)       //boosting title 
            .field("newsText", 0.4f)
            .type(MultiMatchQueryBuilder.Type.BEST_FIELDS)
            .slop(50)
            .fuzziness(Fuzziness.ONE) //80 % of mispelling have an edit distance 1 (Damerau-Levenshtein edit distance)
            )
            .withPageable(new PageRequest(page, 15))
            .build();
    Page<ProvenNews> result = elasticsearchTemplate.queryForPage(searchQuery, ProvenNews.class);//newsSearchRepository.search(searchQuery);
    return result;
    //  return newsSearchRepository.findByNewsTextAndTitle(query,query,new PageRequest(page, 10, Direction.DESC, "newsDate"));
    }

MY repositoy:

public interface ProvenNewsRepository extends ElasticsearchCrudRepository<ProvenNews, Long> {

    public Page<ProvenNews> findByNewsTextAndTitle(String newsText, String Title, Pageable page);


}

任何建议和协助将不胜感激)

0 个答案:

没有答案