一般來說,我對 ElasticSearch 和 NoQSL 還很陌生。我的問題似乎很簡單,但我似乎無法讓它發揮作用。
我從中獲取的索引看起來像這樣:
"hits" : [
{
"_index" : "movie",
"_type" : "_doc",
"_id" : "255239",
"_score" : 1.0,
"_source" : {
"id" : 255239,
"title" : "Passport to Pimlico",
"original" : "Passport to Pimlico",
"lead" : "",
"text" : "blablabla",
"classification" : 0,
"year" : "1949",
"color" : "b&w",
"duration" : "85",
"url" : "some url",
"slug" : "something something",
"openingDate" : "1900-01-01T00:00:00",
"countries" : [
"GB"
],
"genres" : [
"Comedy",
"Action"
],
"producers" : [ ],
我正在嘗試搜索與此簡單陣列“ [“Thriller”,“Comedy”]中的任何條款上的“流派”屬性中的任何專案匹配的任何記錄。
這是我在控制臺中的查詢:
GET movie/_search
{
"query": {
"terms": {
"genres": ["Thriller", "Comedy"]
}
}
}
此查詢似乎有效,但回傳 0 個結果。我究竟做錯了什么?
任何幫助表示贊賞,謝謝。
uj5u.com熱心網友回復:
試試這個,即查詢genres.keyword而不是genres:
GET movie/_search
{
"query": {
"terms": {
"genres.keyword": ["Thriller", "Comedy"]
}
}
}
uj5u.com熱心網友回復:
這應該有效:
GET movie/_search
{
"query": {
"bool:{
"should": {
"terms":
{
"genres": ["Thriller", "Comedy"]
}
}
}
}
}
ShouldboolQuery 的出現型別將匹配具有提供的任何術語的檔案(因為minimum_should_match默認情況下為 1)。
如果要匹配具有兩種型別的檔案,請使用minimum_should_match: 2
更多檔案:https ://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/481743.html
