ElasticSearch _suggest不返回结果

时间:2015-03-26 17:04:34

标签: elasticsearch

我有一个索引,我希望得到以下建议:

{
    "book": {
        "_index": {
            "enabled": true
        },
        "_id": {
            "index": "not_analyzed",
            "store": "yes"
        },
        "properties": {
            "author": {
                "type": "completion"
            },
            "characters": {
                "type": "string"
            },
            "copies": {
                "type": "long",
                "ignore_malformed": false
            },
            "otitle": {
                "type": "string"
            },
            "tags": {
                "type": "string"
            },
            "title": {
                "type": "string"
            },
            "year": {
                "type": "long",
                "ignore_malformed": false,
                "index": "analyzed"
            },
            "available": {
                "type": "boolean"
            }
        }
    }
}

我使用_bulk端点将一些数据加载到其中。

当我尝试查询建议端点时:

POST library/book/_suggest
{
  "my_suggestion_1":{
    "text": "He",
    "term":{
      "analyzer":"standard",
     "field":"author" 
    }
  }
}

我回来了:

{
   "_index": "library",
   "_type": "book",
   "_id": "_suggest",
   "_version": 8,
   "created": false
}

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

我认为当您提出建议时,您只需在请求正文中使用completion代替term

POST library/book/_suggest
{
  "my_suggestion_1":{
    "text": "He",
    "completion":{
      "analyzer":"standard",
     "field":"author" 
    }
  }
}