0

我正在尝试使用定义的分析器创建一个带有文本和关键字映射的索引,这是我到目前为止所尝试的:


{
    "settings" : {
        "number_of_shards" : 2,
        "number_of_replicas" : 1
    },

    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  ,
    "mappings": {
    "properties": {
  "question": {
    "type":"text",
    "fields": {
      "keyword": {
        "type": "keyword"
      },
     "normalize": {
      "type": "keyword",
      "normalizer": "my_normalizer"
    }

}
}
}
}
}

我已经尝试过了,但出现错误:

"error": {
    "root_cause": [
        {
            "type": "parse_exception",
            "reason": "unknown key [analysis] for create index"
        }
    ],
    "type": "parse_exception",
    "reason": "unknown key [analysis] for create index"
},
"status": 400

}

问题是我需要添加此映射的字段。我正在 AWS ES 服务中尝试这个。

4

1 回答 1

1

很好的开始,你就快到了!

analysis部分需要位于顶级settings部分内,如下所示:

{
  "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 1
    },
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "question": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "normalize": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      },
      "answer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "normalize": {
            "type": "keyword",
            "normalizer": "my_normalizer"
          }
        }
      }
    }
  }
}
于 2020-01-30T14:33:46.173 回答