完成类型不接受对象数组

时间:2018-01-11 09:32:53

标签: elasticsearch type-ahead

我尝试基于Elasticsearch创建一个提前输入功能。但我无法像文档https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-completion.html#completion-suggester-mapping

中所述创建文档

这是我的转储:

这是我的模板

PUT /_template/infinity-index
{
    "template": "infinity-index-*",
    "settings": {},
    "mappings": {
      "*": {
        "properties": {
          "id": {
            "type": "integer"
          },
          "status": {
            "type": "keyword",
            "index": true
          },
          "manufacturer": {
            "type": "text",
            "index": true
          },
          "suggest": {
            "type": "completion"
          }
        }
      }
    }
}

然后我发送批量请求(这里只有一个文件):

POST _bulk
{"create":{"_id":"60003","_index":"infinity-index-2018-01-13","_type":"default"}}
{"id":60003,"status":"active","manufacturer":"WMV","suggest":[{"input": "WVM", "weight": 0}]}

我收到此错误:

{
  "took": 64,
  "errors": true,
  "items": [
    {
      "create": {
        "_index": "infinity-index-2018-01-13",
        "_type": "default",
        "_id": "60003",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "[suggest] is defined as an object in mapping [default] but this name is already used for a field in other types"
        }
      }
    }
  ]
}

任何人都可以给我一个提示,我做错了什么?感谢

1 个答案:

答案 0 :(得分:0)

正如错误所示'建议'字段已经在现有记录上有不同的类型,因此ES无法输入新记录。如果您在此索引中有相关数据,请尝试在新索引中进行测试,如果它不相关,则只需删除并重新创建索引并继续测试。
当我试图在同一个字段上存储数字和字符串并且没有匹配的记录丢失时,我遇到了同样的问题。

修改

好的,我做了更多的研究而且我不知道为什么会说这个错误,但我检查了这个页面:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
我试着在没有你的批量命令的情况下做你做的事情,而是我这样做了:

PUT /_template/infinity-index
{
    "template": "infinity-index-*",
    "settings": {},
    "mappings": {
      "*": {
        "properties": {
          "id": {
            "type": "integer"
          },
          "status": {
            "type": "keyword",
            "index": true
          },
          "manufacturer": {
            "type": "text",
            "index": true
          },
          "suggest": {
            "type": "completion"
          }
        }
      }
    }
}

PUT infinity-index-2018-01-13/type1/1?refresh
{
  "suggest" : [ "WMV", "notWMV"]
}

POST infinity-index-2018-01-13/_search?pretty
{
    "suggest": {
        "manufacture-suggest" : {
            "prefix" : "w", 
            "completion" : { 
                "field" : "suggest" 
            }
        }
    }
}

结果如下:

{
  ...
  "suggest": {
    "manufacture-suggest": [
      {
        "text": "w",
        "offset": 0,
        "length": 1,
        "options": [
          {
            "text": "WMV",
            "_index": "infinity-index-2018-01-13",
            "_type": "type1",
            "_id": "1",
            "_score": 1,
            "_source": {
              "suggest": [
                "WMV",
                "notWMV"
              ]
            }
          }
        ]
      }
    ]
  }
}

这是你试图实现的目标吗?