2017-02-08 9 views
0

私は接続するために一致する必要がありますクエリは、弾性検索で動作していない

マイクエリ継ぎ目を の「シャイニング」だけでなく、PARENT_ID = 189とし、PARENT_TYPEは=「フォルダ」の名前を持つすべてのビデオを見つけるために抱き合わせていますすべての一致ステートメントが「AND」ではなく「OR」

私は間違っていますか?

{ 
    "fields": ["name","parent_id","parent_type"], 
    "query": { 

    "and": { 
     "must":[ 
     { 
      "match": { 
      "name": "The Shining" 
      } 
     }, 
     { 
     "match": { 
      "parent_id": 189 
     } 
     }, 
     { 
      "match": { 
      "parent_type": "folder" 
      } 

     } 
     ] 
    } 
} 
} 

マッピング:

{"video" : { 
"mappings" : { 
    "video" : { 
    "properties" : { 
     "homepage_tags" : { 
     "type" : "nested", 
     "properties" : { 
      "id" : { 
      "type" : "integer" 
      }, 
      "metaType" : { 
      "type" : "string" 
      }, 
      "tag_category_name" : { 
      "type" : "string" 
      }, 
      "tag_category_order" : { 
      "type" : "integer" 
      }, 
      "tag_name" : { 
      "type" : "string" 
      } 
     } 
     }, 
     "id" : { 
     "type" : "integer" 
     }, 
     "name" : { 
     "type" : "string" 
     }, 
     "parent_id" : { 
     "type" : "integer" 
     }, 
     "parent_type" : { 
     "type" : "string" 
     }, 
     "provider" : { 
     "type" : "string" 
     }, 
     "publish" : { 
     "type" : "string" 
     }, 
     "query" : { 
     "properties" : { 
      "bool" : { 
      "properties" : { 
       "must" : { 
       "properties" : { 
        "match" : { 
        "properties" : { 
         "name" : { 
         "type" : "string" 
         }, 
         "parent_id" : { 
         "type" : "long" 
         } 
        } 
        } 
       } 
       } 
      } 
      } 
     } 
     }, 
     "source_id" : { 
     "type" : "string" 
     }, 
     "subtitles" : { 
     "type" : "nested", 
     "include_in_root" : true, 
     "properties" : { 
      "content" : { 
      "type" : "string", 
      "store" : true, 
      "analyzer" : "no_stopwords" 
      }, 
      "end_time" : { 
      "type" : "float" 
      }, 
      "id" : { 
      "type" : "integer" 
      }, 
      "parent_type" : { 
      "type" : "string" 
      }, 
      "start_time" : { 
      "type" : "float" 
      }, 
      "uid" : { 
      "type" : "integer" 
      }, 
      "video_id" : { 
      "type" : "string" 
      }, 
      "video_parent_id" : { 
      "type" : "integer" 
      }, 
      "video_parent_type" : { 
      "type" : "string" 
      } 
     } 
     }, 
     "tags" : { 
     "type" : "nested", 
     "properties" : { 
      "content" : { 
      "type" : "string" 
      }, 
      "end_time" : { 
      "type" : "string" 
      }, 
      "id" : { 
      "type" : "integer" 
      }, 
      "metaType" : { 
      "type" : "string" 
      }, 
      "parent_type" : { 
      "type" : "string" 
      }, 
      "start_time" : { 
      "type" : "string" 
      } 
     } 
     }, 
     "uid" : { 
     "type" : "integer" 
     }, 
     "vid_url" : { 
     "type" : "string" 
     } 
    } 
    } 
}}} 
+0

使用しているESのバージョンは? –

答えて

0

私は上記のVolodymryrsの答えを読んで問題を解決することができました。

"the"と一致していたため、一致が見つかりました。私は演算子の引数を追加しようとしましたが、残念ながらそれは機能しませんでした。代わりに "match_phrase"を使用し、他の2つの一致フィールドを "term"に変更しました。以下の回答を参照してください。

[ 
      'query' => [ 
       'bool' => [ 
        'must' => [ 
         [ 
          'match_phrase' => [ 
           'name' => $searchTerm 
          ] 
         ], 
         [ 
          'term' => [ 
           'parent_id' => intVal($parent_id) 
          ] 
         ], 
         [ 
          'term' => [ 
           'parent_type' => strtolower($parent_type) 
          ] 
         ] 

        ] 
       ] 
      ] 
     ]; 
0

あなたは理由matchクエリのを輝かまたはのマッチを取得し、あなたがスコアを取得します試合に依存します。一番簡単な修正の1つは演算子:とを追加することです。これはまた、または「太陽が輝いている」「輝く」の名前と一致しますので、何が必要

{ 
    "match": { 
     "name": "The Shining", 
     "operator": "and" 
    } 
} 

しかし、そのありません。あなたが名前の完全一致を行う必要がある場合

その他のオプションがあり、その後、あなたは、私がお勧めする以外にkeyword

としてフィールドタイプを設定することができES 5で分析非としてフィールドを作成する必要がありますあなたは完全一致を行うので、boolクエリをタームクエリで使用するようにします。

{ 
    "fields": ["name","parent_id","parent_type"], 
    "query": { 
     "bool": { 
      "must":[{ 
       "term": { 
       "name": "The Shining" 
       } 
      }, 
      { 
      "term": { 
       "parent_id": 189 
      } 
      }, 
      { 
       "term": { 
       "parent_type": "folder" 
       } 

      } 
      ] 
     } 
    } 
} 
+0

"the"と一致しているため、一致するものが見つかりましたので、あなたの説明をお寄せいただきありがとうございます。私は演算子の引数を追加しようとしましたが、残念ながらそれは機能しませんでした。私が代わりに使ったのは "match_phrase"を使うことでした。また、私の2つの他のマッチフィールドを "term"に切り替えました - 以下の私の答えを見てください –

関連する問題