完成类型不接受对象数组



我尝试创建一个基于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"
        }
      }
    }
  ]
}

谁能给我一个提示,我做错了什么?谢谢

由于错误显示"建议"字段在现有记录上已经具有不同的类型,因此 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"
              ]
            }
          }
        ]
      }
    ]
  }
}

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

最新更新