2016-07-26 92 views
0

當前堆棧涉及的node.js v0.12.7elasticsearch-JS> = 1.1.0Elasticsearch 1.7 API運行。Elasticseach完成建議者返回建議

我當前elasticsearch設置被映射到具有索引1與2種類型:

elasticsearch.client.indices.create({ 
     index: 'randomindex', 
     body: { 
     "settings": { 
      "analysis": { 
      "filter": { 
       "autocomplete_filter": { 
       "type": "edge_ngram", 
       "min_gram": 1, 
       "max_gram": 20 
       } 
      }, 
      "analyzer": { 
       "autocomplete": { 
       "type": "custom", 
       "tokenizer": "standard", 
       "filter": [ 
        "lowercase", 
        "autocomplete_filter" 
       ] 
       }, 
       "my_english": { 
       "type":  "english", 
       "stopwords": "_english_" 
       } 
      } 
      } 
     }, 
     'mappings': { 
      'countries': { 
      'properties': { 
       'country': { 
       'type': 'string', 
       'fields': { 
        "autocomplete": { "type": "string", "index_analyzer": "autocomplete", "search_analyzer": "my_english" } 
       } 
       }, 
       "suggest_countries": { 
       "type": "completion", 
       "index_analyzer": "simple", 
       "search_analyzer": "simple", 
       "payloads": true 
       } 
      } 
      }, 
      'some_other_type': { 
      'properties': { 
       "field_1": { 
       "type": "date" 
       }, 
       "field_2": { 
       "type": "string" 
       }, 
       "suggest_some_other_field": { 
       "type": "completion", 
       "index_analyzer": "simple", 
       "search_analyzer": "simple", 
       "payloads": false 
       } 
      } 
      } 
     } 
     } 
    }); 

我已經然後填充有相關的「輸入」,「輸出」和「有效載荷」字段都建議字段。

我想指定特定的索引類型從返回的建議,但我這樣做時,它拋出的錯誤:

elasticsearch.clients.suggest({ 
    index: "randomindex", 
    type: "countries", 
    body: { 
     "suggest": { 
     text: query, 
     completion: { 
      "field": "suggest_countries" 
     } 
     } 
    } 
    }); 

有什麼辦法我可以指定/指向特定類型的。建議方法?

+0

請分享錯誤ES扔。 – Val

+0

當我在節點上運行它時沒有錯誤。它只是在響應對象中返回一個空的選項數組。然而,當我嘗試通過谷歌瀏覽器的Sense擴展等客戶端訪問'/ randomindex/countries/_suggest'端點時,我傳遞了類似'{「suggest_countries」:{「text」:「a」,「completion」:{ 「field」:「suggest_countries」}}}'它會拋出一個錯誤,如'MapperParsingException [解析失敗];嵌套:ElasticsearchIllegalArgumentException [未知字段名稱[文本],必須是[輸出,上下文,輸入,重量,有效載荷]];'中的一個。 –

+0

我可以確保我已經在'autocomplete_countries'類型中正確填充'suggest_countries'字段,因爲我已經在端點'/ randomindex/countries/_search'上檢查了Sense,並且一切似乎都在那裏。 –

回答

0

你需要讓你的呼叫而不type參數

elasticsearch.clients.suggest({ 
    index: "randomindex", 
    body: { 
     "suggest": { 
     text: query, 
     completion: { 
      "field": "suggest_countries" 
     } 
     } 
    } 
    }); 

看到官方文檔的client.suggest() call,沒有可用的type參數。

+0

這有什麼好運氣? – Val