0

我正在尝试将 _analyze api 与如下所示的文本一起使用:

--- some -- text ---

此请求按预期工作:

curl localhost:9200/my_index/_analyze -d '--'
{"tokens":[]}

但是,这个失败了:

curl localhost:9200/medical_documents/_analyze -d '---'
---
error:
  root_cause:
  - type: "illegal_argument_exception"
    reason: "Malforrmed content, must start with an object"
  type: "illegal_argument_exception"
   reason: "Malforrmed content, must start with an object"
status: 400

考虑到响应的格式,我假设 elasticsearch 尝试将请求解析为 yaml 并失败。

如果是这种情况,我如何禁用 yml 解析或_analyze以 开头的文本---

4

1 回答 1

1

问题不在于 yaml 解析器。问题是您正在尝试创建一个类型。
以下是不正确的
(会给你Malforrmed content, must start with an object error
curl localhost:9200/my_index/medical_documents/_analyze -d '---'

这不会给你错误,但不正确。因为它会告诉 elastic 创建一个新类型。
curl localhost:9200/my_index/medical_documents/_analyze -d '{"analyzer" : "standard","text" : "this is a test"}'

分析器是在索引级别创建的。验证:
curl -XGET 'localhost:9200/my_index/_settings'<br/>

所以正确的做法是: curl -XGET 'localhost:9200/my_index/_analyze' -d '{"analyzer" : "your_analyzer_name","text" : "----"}'
以前需要创建分析器。

于 2017-02-21T15:07:02.173 回答