0

I have two indices: X and Y I need to search on X index and run suggest on Y.

Mapping for 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',
    ]
]

I search for products in X, get aggregated data, and in the same query run the suggester to search for previous queries from index Y (autosuggest query)

Query:

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
           }
        }
     }
  }

I get the exception

["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]"
  }
}

Anyone? Thanks

Moghira
  • 317
  • 5
  • 10

1 Answers1

0

I dont know if your case is valid (run query on X and suggester on Y) but if you look exception trace carefully you can see it fails on X index:

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

In documentation it says:

The suggestions are gathered in the query phase

so I guess it fires that exception because it runs query on X index and cant find that field on it.

alpert
  • 4,500
  • 1
  • 17
  • 27