【问题标题】:Elasticsearch on Jhipster, SpringJhipster 上的 Elasticsearch,Spring
【发布时间】:2015-07-14 07:48:39
【问题描述】:

谁能给我在 jHipsterSpring-boot 中使用 Elasticsearch 的例子吗?

我已经使用 jHipster 生成了实体。有占位符的输入:查询!

/**
     * 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());
    }

如何使用elasticsearch?

这是我在生成的实体中找到的一些脚本!

我已经尝试过放置 Objectq=field:value具有弹性格​​式的数组,但总是得到空 Array。

抱歉英语不好!

【问题讨论】:

    标签: java spring elasticsearch spring-boot jhipster


    【解决方案1】:

    好吧,您的索引似乎是空的。如果您以编程方式(即不是从界面)添加实体,请务必将它们也保存在搜索存储库中。

    例子:

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

    您需要重新影响 sample 以使 Hibernate 生成的 id 在 elasticsearch 中正确索引。

    2016 年 10 月 2 日更新

    现在有一个JHipster module to reindex elasticsearch repositories

    【讨论】:

      【解决方案2】:

      您应该通过将 placeolder 替换为您要在“示例”实体中搜索的字符串来对 url 进行 GET 调用。

      您可以使用 rest 客户端(例如,用于 firefox 的 restclient 插件)或 curl 来测试调用。 网址应该是这样的:

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

      您将获得 json 格式的结果。

      如果您需要自定义默认搜索行为,请查看 Spring 上的 Elasticsearch 文档:

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

      【讨论】:

        猜你喜欢
        • 2016-01-02
        • 2018-11-26
        • 2016-04-13
        • 2016-09-02
        • 1970-01-01
        • 2018-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多