【问题标题】:Elasticsearch 6.1 Java API search issueElasticsearch 6.1 Java API 搜索问题
【发布时间】:2018-01-03 06:59:09
【问题描述】:

我正在使用 ES - 6.1 和相应的 java 版本的 api。我能够使用 java API 对数据进行索引。我通过 kibana 验证了这一点。所有映射均已正确保存,但当我尝试搜索时出现错误。即使是最基本的搜索也会返回一个空集合。

// client is a reference to the TransportClient instance
SearchResponse searchResponse = this.client.prepareSearch(index).get().

当我尝试通过 getFields() 获取字段并进一步执行 getField(key) 时,我得到一个空指针异常。我尝试了故障排除,发现在响应中没有返回任何对象。以下是我正在做的基本搜索。

// index is the index I am interested to search under.
SearchResponse searchResponse = this.client.prepareSearch(index).get();

这是我在尝试将代码从 1.7.3 Java API 迁移到最新版本时遇到的问题。早些时候,我们的实施没有发现任何问题。

我已经阅读了很多关于为此发生的变化的文章,但没有找到适用于我的案例的解决方案。

我已经使用存储映射的每个属性集重新索引了我的数据。我仍然没有得到我感兴趣的字段的响应。字段 Keyset 仍然是空值

以下是映射示例。

"street": {
    "type": "text",
    "store": true
},
"country": {
    "type": "text",
    "store": true
},
"city": {
    "type": "text",
    "store": true
}
---------------Some more fields--------------

附上调试器中我的变量的屏幕截图。 }

这是我在进行故障排除时收到的每次点击的响应。我在该索引中获得了正确的点击数。从调试器附加我的变量的屏幕截图。 hits 是包含来自以下代码的响应的变量。

hits = searchResponse.getHits()

Debugger log for the values "hits" hold

感谢您的帮助。

-阿吉特

【问题讨论】:

    标签: java elasticsearch elasticsearch-6


    【解决方案1】:

    我发现问题出在搜索方法上。

    与以前的版本不同,新版本将以不同的方式获取地图中的命中。

    //in previous version (1.7.3)
    hit.getFields() 
    // in new version (6.1.0)
    hit.getSourceAsMap()
    

    进一步,我们可以像之前那样反序列化响应。

    这里是link弹性搜索论坛,其中包含所有详细信息。感谢您的帮助。

    -阿吉特

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多