【问题标题】:Issues with elasticsearch using play framework使用播放框架的弹性搜索问题
【发布时间】:2012-05-11 09:21:00
【问题描述】:

我是 Play 和 ElasticSearch 的新手,一直在尝试为 POC 配置它们。我使用了 CRUD 模块(Play 1.2.4)并创建了一个名为 Book 的模型

@ElasticSearchable
@Entity
public class Book extends Model{

    @Required
    public String title ;
    @Required
    public String author ;
    @Required
    public String publisher ;
    public String binding ;
    @Required
    public double price ;
    public double discount ;
    @Required
    @MaxLength(4)
    public String releasedYear ;
    @Required
    public boolean inStock ;
    public String language ;
    public String deliveryTime ;
}

并在内存数据库 H2 中创建了一些记录,并在 elasticsearch 节点中对这些记录进行了索引(我正在使用本地机器运行 ES)

当我尝试使用 ES 管理界面(我们在 Play 中使用 ES 模块时默认提供)进行搜索时,我遇到了一个奇怪的问题

我有一本书的标题是“Java 初学者”,我正在尝试从 ES-Admin 界面对字段标题运行术语查询。

{"query" : {"term" : { "title" : "Java for beginners" }}}

它还给我

{
took: 3
timed_out: false
_shards: {
total: 5
successful: 5
failed: 0
}
hits: {
total: 0
max_score: null
hits: [ ]
}
}

这本质上意味着没有匹配的记录

奇怪的是,当我将查询更改为

{"query" : {"term" : { "title" : "beginners" }}}

它返回给我的记录如下

{
took: 3
timed_out: false
_shards: {
total: 5
successful: 5
failed: 0
}
hits: {
total: 1
max_score: 0.19178301
hits: [
{
_index: models_book
_type: models_book
_id: 1
_score: 0.19178301
_source: {
title: Java for beginners
author: Bruce Eckel
publisher: Timburys
binding: Paperback
price: 450
discount: 10
releasedYear: 2010
inStock: true
language: English
deliveryTime: 3 days
id: 1
}
}
]
}
}

如果有人能对此有所了解,那将是非常有帮助的。任何正确方向的帮助将不胜感激

谢谢

【问题讨论】:

    标签: java search playframework elasticsearch


    【解决方案1】:

    使用term query 时,不分析正在搜索的词条,这意味着通常它应该是一个词条。如果要查询需要分析的字符串,应该使用query_string query type

    这个查询应该适合你:

    curl -s "localhost:9200/test/_search" -d '
    {
      "query":{
        "query_string":{
          "query":"Java for beginners"
        }
      }
    }'
    

    【讨论】:

      猜你喜欢
      • 2023-01-14
      • 1970-01-01
      • 2011-09-09
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多