2012-05-11 45 views
0

我是Play和ElasticSearch的新手,並且一直在嘗試將它們配置爲POC。我已經使用了CRUD模塊(播放1.2.4),並創建了一個名爲書彈性搜索使用播放框架的問題

@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管理界面做搜索(默認情況下提供的,當我們使用在播放的ES模塊),我已經在一個奇怪的問題

我打有一本書名爲「Java for beginners」的書,我試圖從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 
} 
} 
] 
} 
} 

如果有人能夠對此有所瞭解,這將有很大的幫助。在正確的方向任何幫助,將不勝感激

感謝

回答

2

當使用term query,所搜索不分析術語,意思通常它應該是一個單一的術語。如果您想查詢需要分析的字符串,則應使用query_string query type

此查詢應該爲你工作:

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

謝謝,成功了! – Rocky