Elasticsearch教程或搜索(必须和应该结合)

时间:2017-11-15 18:58:23

标签: elasticsearch kibana

开始使用elasticsearch和kibana我尝试了本教程。但现在我得到了一个我无法自行解决的错误。

这个非常熟悉:elasticsearch bool query combine must with OR

但Daniel Fackrell的解决方案对我来说并不起作用,我显然遗漏了一些东西。我的代码:

POST shakespeare/scene/_search/
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "play_name": "Antony"
          },
          "bool": {
            "should": [
              {
                "match": {
                  "speaker": "Demetrius"
                }
              },
              {
                "match": {
                  "speaker": "Antony"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

然后我收到以下错误:" [匹配]格式错误的查询,预期[END_OBJECT]但找到[FIELD_NAME]"

搜索并环顾四个小时后,我希望有人可以帮助我。

我正在使用5.6.4版。

提前致谢!

亲切的问候 格雷格

1 个答案:

答案 0 :(得分:0)

我想你错过了一个支架。检查下面的查询。

POST shakespeare/scene/_search/
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "play_name": "Antony"
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "speaker": "Demetrius"
                }
              },
              {
                "match": {
                  "speaker": "Antony"
                }
              }
            ]
          }
        }
      ]
    }
  }
}