简体   繁体   English

奇怪的输出查询弹性搜索

[英]Strange output query Elastic Search

I just started with using Elastic Search. 我刚开始使用弹性搜索。 I've got everything set-up correctly. 我已经正确设置了所有设置。 I'm using Firebase + Flashlight + Elastic Search. 我正在使用Firebase + Flashlight + Elastic Search。

In my front-end I'm building queries based on different search params. 在前端,我基于不同的搜索参数构建查询。 I insert them into a node in Firebase /search/requests/ . 我将它们插入Firebase /search/requests/的节点中。 Flashlight will pick this up and putting the response into /search/response , this works like a charm! Flashlight会捡起来并将响应放入/search/response ,这就像一个魅力!

However, I'm not sure how to write my queries properly. 但是,我不确定如何正确编写查询。 I'm getting strange results when I'm trying to combine two must match queries. 当我尝试合并两个must match查询时,我得到的结果很奇怪。 I'm using Query DSL. 我正在使用查询DSL。

My documents in Elastic Search under deliverables/doc are having the following scheme. 我在Elastic Search中的deliverables/doc下的deliverables/doc具有以下方案。

...
{
  "createdBy" : "admin@xx.org",
  "createdOn" : 1501200000000,
  "deadLine" : 1508716800000,
  "description" : {
    "value" : "dummy description"
  },
  "key" : "<FBKEY>",

  "programmes" : [ {
    "code" : "95000",
    "name" : "Test programme",
    "programYear" : 2017
  } ],
  "projects" : [ {
    "projectCode" : "113200",
    "projectName" : "Test project",
    "projectYear" : 2017
  } ],
  "reportingYear" : 2017,
  "status" : "Open",
  "type" : "writing",
  "updatedBy" : "admin@xx.org",
  "updatedOn" : 1501200000000,
},
...

My query has the following structure. 我的查询具有以下结构。

{
   "query": {
    "bool": {
      "must": [
        {
          "match": {
            "createdBy": "xx@company.org"
          },
          "match": {
            "programmes.code": "95000"
          }
        }
      ]
    }
  }
}

In my output I'm also getting documents that don't have exactly those two fields? 在我的输出中,我还得到了不完全具有这两个字段的文档? They have a very low score as well. 他们的分数也很低。 Is this normal? 这正常吗?

My mapping, automatically created using Flashlight 我的地图,使用Flashlight自动创建

在此处输入图片说明

Update 1 更新1

I just tried this query, however it still gives me strange results by not filtering on both fields: 我只是尝试了此查询,但是通过不对两个字段进行过滤,它仍然给我带来奇怪的结果:

   {
   "query": {
      "bool": {
         "filter": {
            "bool": {
               "must": [
                  {
                     "match": {
                        "programmes.code": "890000"
                     }
                  },
                  {
                     "match": {
                        "createdBy": "admin@xx.org"
                     }
                  }
               ]
            }
         }
      }
   }
}

The must clause used in bool query is executed in query context (all the documents are returned in decreasing order of score) and contributes to score. bool query使用的must子句在查询上下文中执行(所有文档以得分的降序返回)并有助于得分。 see link 见链接

If you want it to be executed as a filter, then use the following query: 如果希望将其作为过滤器执行,请使用以下查询:

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "match": {
                "createdBy": "xx@company.org"
              }
            },
            {
              "match": {
                "programmes.code": "95000"
              }
            }
          ]
        }
      }
    }
  }
}

NOTE: 注意:

By default the string field is analyzed, update the mapping of the string fields as not_analyzed , to use filter query. 默认情况下,将分析字符串字段,将字符串字段的映射更新为not_analyzed ,以使用filter查询。 Refer: mapping-intro 参考: mapping-intro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM