建议搜索多个索引给出" ElasticsearchException [Field []不是完成建议字段]"

时间:2016-05-05 14:06:06

标签: php elasticsearch multi-index completion

我有两个指数:X和Y. 我需要搜索X索引并在Y上运行建议。

Y的映射

$config['params']['suggestion']['body']['mappings']['suggester'] = [
'properties' =>
 [
    'search_id' => [
        'type' => 'string',
        'index' => 'not_analyzed'
    ],
    'autosuggest_query' => [
        'type'  => 'completion',
        "analyzer" => "my_suggester_analyzer",
  "search_analyzer" => "my_suggester_analyzer",
        "preserve_separators" => "false",
        "preserve_position_increments" => "false",
  "payloads" => true
    ],
    'product_count' => [
        'type'  => 'integer',
    ],
    'search_count' => [
        'type'  => 'integer',
    ]
]

我在X中搜索产品,获取聚合数据,并在同一查询中运行建议器以搜索索引Y(autosuggest查询)中的先前查询

查询:

GET _search
{ 
  "query": {
         "filtered": {
            "query": {
               "bool": {
                  "should": {
                     "multi_match": {
                        "type": "phrase",
                        "query": "dinning table cover",
                    "fields": [
                       "q1^20",
                       "q2^10"
                    ],
                    "slop": "3"
                 }
              }
           }
        }
     }
  },
  "size": 0,
  "aggs": {
     "category_L1": {
        "terms": {
           "field": "product_root_category_slug",
           "size": 2,
           "min_doc_count": 1
        },
        "aggs": {
           "category_L2": {
              "terms": {
                 "field": "product_main_category_slug",
                 "size": 1,
                 "min_doc_count": 1
              },
              "aggs": {
                 "category_L3": {
                    "terms": {
                       "field": "category_slug",
                       "size": 1,
                       "min_doc_count": 1
                    },
                    "aggs": {
                       "cat_name": {
                          "terms": {
                             "field": "category.raw"
                          }
                       }
                    }
                 }
              }
           }
        }
     }
  },
  "suggest": {
     "suggester_a": {
        "text": "dinning table cover",
        "completion": {
           "field": "autosuggest_query",
           "fuzzy": {
              "fuzziness": 0
           }
        }
     }
  }

我得到了例外

["failures"]=>
  array(1) {
  [0]=>
  array(4) {
    ["index"]=>
    string(18) "X"
    ["shard"]=>
    int(0)
    ["status"]=>
    int(500)
    ["reason"]=>
    string(83) "ElasticsearchException[Field [autosuggest_query] is not a completion suggest field]"
  }
}

任何? 感谢

1 个答案:

答案 0 :(得分:0)

我不知道你的情况是否有效(在X上运行查询和在Y上运行建议)但是如果仔细查看异常跟踪,你可以看到它在X索引上失败:

...
["index"]=>
string(18) "X"
["shard"]=>
...

在文档中说:

  

建议在查询阶段收集

所以我猜它会触发该异常,因为它在X索引上运行查询而无法在其上找到该字段。