编写包含8000个以上关键字的查询,以检索包含这些关键字的唯一记录

时间:2017-09-26 19:47:30

标签: linux elasticsearch

我对弹性搜索和Linux都是全新的。因为2个星期前的一个项目,我开始学习它们。所以,对不起,如果我的问题太简单了。 我正在尝试编写一个查询,以帮助我根据存储库中的关键字列表(8000个关键字)找出返回的唯一记录的数量。这是我想出的代码。这是我想出的代码:

 curl http://localhost:9200/INDEXED_REPOSITORY/_search?q="constant_score" : {"filter" : { "terms" : { "description" : ["heart", "cancer", and 7000 more keywords that I just pasted here]}}}}

但我收到以下错误:

Couldn't resolve host 'constant_score'
curl: (6) Couldn't resolve host ':'
curl: (3) [globbing] unmatched brace at pos 8

curl: (6) Couldn't resolve host ':'
curl: (3) [globbing] unmatched brace at pos 2

curl: (6) Couldn't resolve host 'terms'
curl: (6) Couldn't resolve host ':'
curl: (3) [globbing] unmatched brace at pos 2

我不明白我做错了什么。这有什么解决方案吗?

1 个答案:

答案 0 :(得分:0)

我更喜欢使用curl的-d选项而不是查询字符串来传递查询。 这应该有效:

curl -XGET "http://localhost:9200/INDEXED_REPOSITORY/_search" -d'
{
  "query": {
    "constant_score": {
      "filter": {
        "terms": {
          "description": [
            "heart",
            "cancer"
          ]
        }
      }
    }
  }
}'