无法创建索引

时间:2016-06-04 13:24:13

标签: elasticsearch

我尝试完全按照此答案中所示创建测试索引...

Elasticsearch layered ordering

PUT /test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "ngram"
          ]
        },
        "search_ngram": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": "lowercase"
        }
      },
      "filter": {
        "ngram": {
          "type": "ngram",
          "min_gram": 2,
          "max_gram": 15
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "text": {
          "type": "string",
          "index_analyzer": "autocomplete",
          "search_analyzer": "search_ngram",
          "index_options": "positions",
          "fields": {
            "not_analyzed_sorting": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}

但是我得到了错误。如果我删除这两行,那么我可以创建索引,但这不会返回正确的结果。

  "index_analyzer": "autocomplete",
  "search_analyzer": "search_ngram",

错误是:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "analyzer on field [text] must be set when search_analyzer is set"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "Failed to parse mapping [test3]: analyzer on field [text] must be set when search_analyzer is set",
      "caused_by": {
         "type": "mapper_parsing_exception",
         "reason": "analyzer on field [text] must be set when search_analyzer is set"
      }
   },
   "status": 400
}

我使用crome的感知扩展,我的elasticsearch服务器是托管在Amazon ec2实例上的。

我想知道创建索引的正确方法是什么,如答案中所示。

1 个答案:

答案 0 :(得分:1)

而不是

"index_analyzer": "autocomplete", 

尝试:

"analyzer":"autocomplete"

您可以将search_analyzer设为standard

有关类似的用例,请参阅this