2017-06-09 3 views
0

Dies ist meine Abfrage in symfony2. Ich möchte hier "match_phrase" hinzufügen, aber überall, dass ich hinzufügen, erhalte ich Fehler.Wie match_phrase mit constant_score zu verwenden ist, Begriffe

$params = [ 
    'index' => 'articles_v2', 
    'type' => 'article', 
    'body' => [ 
     "sort" => [ 
      [ "date" => 
       ["order" => "desc"] 
      ], 
     ], 
     "from" => $fromId, 
     "size" => $newsPerPage, 
     "query" => [ 
      "constant_score" => [ 
       "filter" => [ 
        "bool" => [ 
         "must" => [ 
          ["terms" => [ "article.topics" => $topics ] ], 
          ["match_phrase" => ["article.bodytext" => [$search_phrase] ]] 
         ] 
        ] 
       ] 
      ] 

     ] 
    ] 
]; 
$response = $client->search($params); 

Wenn ich versuche, dies zu laufen, bekomme ich Fehler: verschachtelte: QueryParsingException [[articles_v2] Kein Filter registriert für [match_phrase]]; }]“, "Status":. 400

Also, wo diese match_phrase platzieren (Ich will Ergebnisse wie SQL LIKE '% xxxx%' erhalten)


ich die Abfrage geändert haben diese Zeit keine Fehler, aber wie auch immer, keine Filtration.

$params = [ 
    'index' => 'articles_v2', 
    'type' => 'article', 
    'body' => [ 
     "sort" => [ 
      [ "date" => 
       ["order" => "desc"] 
      ], 
     ], 
     "from" => $fromId, 
     "size" => $newsPerPage, 
     "query" => [ 
      "constant_score" => [ 
       "filter" => [ 
        "bool" => [ 
         "must" => [ 
          ["terms" => [ "article.topics" => $topics ] ] 
         ] 
        ] 
       ], 
       "query" => [ 
        "multi_match" => [ 
         "query" => $search_phrase, 
         "fields" => [ "title", "bodytext" ] 
        ] 
       ] 
      ] 
     ] 
    ] 
]; 
$response = $client->search($params); 

Antwort

0

Die Lösung ist nicht Spiel mit konstanter Punktzahl verwenden.

Sie haben Abfrage/bool verwenden/muss und all dies übereinstimmen und andere Bedingungen im Inneren müssen.

Hier ist der Code.

$params = [ 
    'index' => 'articles_v2', 
    'type' => 'article', 
    'size' => 50, 
    'body' => [ 
     "sort" => [ 
      [ "date" => 
       ["order" => "desc"] 
      ], 
     ], 
     "from" => $fromId, 
     "size" => $newsPerPage, 
     "query" => [ 
      "bool" => [ 
       "must" => [ 
        [ 
         "match_phrase_prefix" => [ 
          "_all" => [ 
           "query" => $search_phrase, 
           "operator" => "and", 
           "analyzer" => "analyzer_cs" 
          ] 
         ] 
        ], 
        ["terms" => [ "article.topics" => $topics ] ], 
        ["range" => [ "article.date" => [ "from" => $date_from,"to" => $date_till]]] 
       ] 
      ] 
     ] 
    ] 
]; 
Verwandte Themen