我正在使用ElasticSearch服務器搜索與所有類型的圖書的書籍ISBN,圖書標題和圖書的主題標題。我做了使用的三種模式具有關係一樣,ElasticSearch搜索查詢具有許多關係模型rails
書hash_many additional_isbns索引,科目
書hash_one aliase
我的索引樣子,
{
"_index":"books","_type":"book","_id":"9781135028411","_score":0.6377245,
"_source":{"book_vbid": "9781135028411","book_title": "Objectivity, Science and Society","book_author":"Paul A Komesaroff",
"additional_isbn": [{"isbn_value": "0415474876"},{"isbn_value": "9780415474870"}],
"aliase": {"eisbn_canonical":"9781135028411","isbn_canonical":"9781135028411","print_isbn_canonical":"9780415474870","isbn13":"9781135028411","isbn10":"1135028419"},
"subjects": [{"title": "General"},{"title": "General"},{"title": "General"},{"title": "Physical & Earth Sciences -> Science -> General"},{"title": "Social Sciences -> Philosophy -> General"},{"title": "Social Sciences -> Social Sciences -> General"}]}},{
"_index":"books","_type":"book","_id":"9781135027896","_score":0.6348529,
"_source":{"book_vbid": "9781135027896","book_title": "Beyond Empiricism","book_author":"Andrew Tudor",
"additional_isbn": [{"isbn_value": "0415475007"},{"isbn_value": "9780415475006"}],
"aliase": {"eisbn_canonical":"9781135027896","isbn_canonical":"9781135027896","print_isbn_canonical":"9780415475006","isbn13":"9781135027896","isbn10":"1135027897"},
"subjects": [{"title": "General"},{"title": "General"},{"title": "General"},{"title": "Physical & Earth Sciences -> Science -> General"},{"title": "Social Sciences -> Philosophy -> General"},{"title": "Social Sciences -> Social Sciences -> General"}]}},{
"_index":"books","_type":"book","_id":"9781134429059","_score":0.6258716,
"_source":{"book_vbid": "9781134429059","book_title": "Your Murderer","book_author":"Vassily Aksyonov",
"additional_isbn": [{"isbn_value": "9057551039"},{"isbn_value": "9789057551031"}],
"aliase": {"eisbn_canonical":"9781134429059","isbn_canonical":"9781134429059","print_isbn_canonical":"9789057551031","isbn13":"9781134429059","isbn10":"1134429053"},
"subjects": [{"title": "General"},{"title": "General"},{"title": "Humanities -> Performing Arts -> General"},{"title": "Humanities -> TheatrGeneral"}]}}
我有搜索方法like,
def self.search(query, options = {})
es_options =
{
query: {
query_string: {
query: query,
default_operator: 'AND',
}
},
sort: '_score',
}.merge!(options)
__elasticsearch__.search(es_options) end
我的要求是就像我在Book.search('general')
上搜索時一樣,搜索必須只針對所有書籍的主題值。 我只能在主題上搜索,而不能在其他列上搜索?
謝謝你的迴應。所以我有要求像我想只搜索所有書籍的所有主題的標題,只需要結果。 – rick
哦,我明白了,我現在正在從手機上打字,但我會建議嘗試將中間的查詢更改爲主題:{title:'general'}而不是主題:「general」。當我回到我的比賽中時,我會更深入地看。 – bkunzi01