简体   繁体   English

Elasticsearch on Jhipster,春季

[英]Elasticsearch on Jhipster, Spring

Can someone give me example for using Elasticsearch in jHipster or in Spring-boot ? 有人可以给我提供在jHipsterSpring-boot中使用Elasticsearch示例吗?

I have already generated entity using jHipster. 我已经使用jHipster生成了实体。 There are input with placeholder :query ! 有占位符:query的输入!

/**
     * SEARCH  /_search/samples/:query -> search for the sample corresponding
     * to the query.
     */
    @RequestMapping(value = "/_search/samples/{query}",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
    @Timed
    public List<Sample> search(@PathVariable String query) {
        return StreamSupport
            .stream(sampleSearchRepository.search(queryString(query)).spliterator(), false)
            .collect(Collectors.toList());
    }

How can use the elasticsearch ? 如何使用elasticsearch?

Here some script that i found in generated Entity! 这是我在生成的Entity中找到的一些脚本!

I have already tried placing Object , q=field:value , Array with elastic format and always got empty Array . 我已经尝试过用弹性格式放置Objectq = field:valueArray,并且始终得到空Array

Sorry for bad english!. 对不起,英语不好!

Well, it seems that your index is empty. 好吧,看来您的索引是空的。 If you add entities programmatically (ie not from the interface), be sure to save them in the search repository as well. 如果您以编程方式添加实体(即不是通过界面添加),请确保也将其保存在搜索库中。

Example : 范例:

Sample sample = new Sample();
sample.setName("bar");
sample = sampleRepository.save(sample);
sampleSearchRepository.save(sample);

You need to reaffect sample to get the id generated by Hibernate correctly indexed in elasticsearch. 您需要重新采样以获取由Hibernate生成的ID在Elasticsearch中正确索引。

UPDATE 10/02/2016 更新10/02/2016

There is now a JHipster module to reindex elasticsearch repositories . 现在有一个JHipster模块可以重新索引elasticsearch存储库

You should just do a GET call to the url by substituting the placeolder with the string that you want to search in the 'sample' entity. 您只需要对URL进行GET调用,方法是将placeolder替换为要在“ sample”实体中搜索的字符串。

You can test the call by using a rest client (eg. restclient plugin for firefox) or curl. 您可以使用其他客户端(例如,用于firefox的restclient插件)或curl测试呼叫。 The url should be something like: 网址应类似于:

http://localhost:8080/_search/samples/queryString

You'll get the results in json format. 您将获得json格式的结果。

If you need to customize the default search behaviour check the Elasticsearch documentation on Spring: 如果您需要自定义默认搜索行为,请查看Spring上的Elasticsearch文档:

http://docs.spring.io/spring-data/elasticsearch/docs/1.0.5.RELEASE/reference/html/elasticsearch.repositories.html http://docs.spring.io/spring-data/elasticsearch/docs/1.0.5.RELEASE/reference/html/elasticsearch.repositories.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM