ElasticSearch - 多匹配查询不返回数据匹配,即使它在那里 - NodeJS

ElasticSearch - Multi-match Query returning no hits for data even though its there - NodeJS

我正在尝试获取具有以下字段的项目列表:resellable: true

这是我的数据集,我可以通过访问看到:my-domain.com/_all/listings/_search

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "collectibles",
        "_type" : "listing",
        "_id" : "SseZfNbpdpBxc3O",
        "_score" : 1.0,
        "_source" : {
          "data" : {
            "resellable" : true,
            "active" : true,
            "description" : "<p>1234 123 123 123</p>",
            "title" : "2134",
            "has_store" : true,
            "createdAt" : "Wed May 27 2020 04:23:18 GMT+0000 (Coordinated Universal Time)",
            "apiURL" : "kJ9zsIsdQG8TZrRfPco4",
            "id" : "SseZfNbpdpBxc3O",
            "state" : "PENDING",
            "amount" : "21",
          }
        }
      }
}

我的查询使用 *NodeJS and ElasticSearch.js*

let results = await client.search({
    index: params.category,
    type: "listing",
    body: {
        query: {
            multi_match: {
                query: true,
                fields: ['resellable', 'active'],
                type: 'best_fields',
            }
        }
    }
})

响应总是no hits。我试过 match,我试过没有 best_fields,它似乎与值不匹配。

我在这里做错了什么?查询 _source.data 级别的项目还需要做些什么吗?

ElasticSearch version: 7.4

您在使用 multi_match 时使用字符串格式的 "true",而您以布尔格式 true 索引数据,这就是您没有获得任何匹配的原因。

我刚刚注意到你的两个 multi_match 字段(resellableactive)都是布尔值那么你为什么要使用 multi_match 查询,你应该改用boolean filter query 也被缓存并提供更好的性能。

来自文档

过滤器子句在过滤器上下文中执行,这意味着忽略评分并考虑对子句进行缓存。

示例索引映射

{
    "mappings": {
        "properties": {
            "active": {
                "type": "boolean"
            },
            "resellable" :{
                "type" : "boolean"
            }
        }
    }
}

索引各种示例文档

{
   "active" : true,
   "resellable" : true
}

{
   "active" : true,
   "resellable" : false
}

{
   "active" : false,
   "resellable" : false
}

{
   "active" : false,
   "resellable" : true
}

搜索查询以获取两个值都为真的文档

{
    "query": {
        "bool": {
            "filter": [
                {
                    "match": {
                        "active": true
                    }
                },
                {
                    "match": {
                        "resellable": true
                    }
                }
            ]
        }
    }
}

结果

 "hits": [
         {
            "_index": "filterbool",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.0,
            "_source": {
               "active": true,
               "resellable": true
            }
         }
      ]