elasticsearch,elastica,foselasticabundle,Php,elasticsearch,Elastica,Foselasticabundle" /> elasticsearch,elastica,foselasticabundle,Php,elasticsearch,Elastica,Foselasticabundle" />

Php 如何将highlight_查询与Elastica/FOSElasticaBundle一起使用?

Php 如何将highlight_查询与Elastica/FOSElasticaBundle一起使用?,php,elasticsearch,elastica,foselasticabundle,Php,elasticsearch,Elastica,Foselasticabundle,我是Elastica的新手,我正在寻找一种使用highlight_query突出显示嵌套查询结果的方法。我检查了代码,$query->setHighlight()只接受数组作为参数。也许有另一种方法可以用Elastica来达到这个效果 这是我试图转换为Elastica的json查询: { "query": { "bool": { "must": [ { "match": { "publ

我是Elastica的新手,我正在寻找一种使用highlight_query突出显示嵌套查询结果的方法。我检查了代码,$query->setHighlight()只接受数组作为参数。也许有另一种方法可以用Elastica来达到这个效果

这是我试图转换为Elastica的json查询:

{
    "query": {
        "bool": {
            "must": [
        {
            "match": {
            "publishAt": "2016"
          }
        },
        {
            "nested": {
            "path": "translations",
            "query": {
                "multi_match": {
                    "query": "leadership",
                "fields": [
                        "translations.*"
                    ]
              }
            }
          }
        },
        {
            "nested": {
            "path": "translations",
            "query": {
                "bool": {
                    "must": [
                  {
                      "match": {
                      "translations.locale": "fr"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "highlight": {
        "highlight_query": {
            "match": {
                "translations.*": "leadership"
      }
    },
    "fields": {
            "translations.*": {}
    }
  }
我使用的是FosElasticaBundle,我有一个没有突出显示的查询:

    $query = new Query();
    $bool = new Bool();

    $yearQuery     = new Match();
    $yearQuery->setField('publishAt', 2016);
    $bool->addMust($yearQuery);

    $nestedQuery  = new Query\Nested();
    $nestedQuery->setPath('translations');

    $multiMatch = new Query\MultiMatch();
    $multiMatch->setQuery($string);
    $multiMatch->setFields('translations.*');
    $nestedQuery->setQuery($multiMatch);

    $nestedQuery2  = new Query\Nested();
    $nestedQuery2->setPath('translations');

    $nestedBool  = new Bool();
    $localeQuery = new Match();
    $localeQuery->setField('translations.locale', $request->getLocale());
    $nestedBool->addMust($localeQuery);
    $nestedQuery2->setQuery($nestedBool);

    $bool->addMust($nestedQuery);
    $bool->addMust($nestedQuery2);

    $query->setQuery($bool);

    $results = $finder->findHybrid($query);

下面是我在Github上描述的解决方案: