【问题标题】:Elasticsearch meaning must using with multimatchElasticsearch 含义必须与 multimatch 一起使用
【发布时间】:2017-10-24 23:22:39
【问题描述】:

这是一个代码

GET /news/_search
{
  "query": {
  "bool": {
     "must": [
        {
           "multi_match": {
              "query": "France and Luxembourg",
              "fields": [
                 "stkno",
                 "tag",
                 "content",
                 "htext"
              ],
              "operator": "and"
           }
        },
        {
           "range": {
              "CDate": {
                 "gt": "2017-05-23T14:02:11",
                 "lte": "2017-05-24T23:59:59"
              }
           }
        }
     ]
  }
 },
    "from": 0,
       "size": 100,
    "sort": [
  {
     "CDate": {
        "order": "desc"
     }
  }
  ]
 }

使用上述命令后,命中总数为 2 条记录。但是一个有确切的单词“France and Luxembourg”,另一个只有“France”。

我的问题如下:

  1. 已经使用“必须”,为什么不只显示“法国和卢森堡”这个词?
  2. 操作员的目的是什么? elasticsearch我已经看过了,但是实在看不懂,能不能多解释一下?

重新编辑:

我尝试使用如下编码,但结果为空。enter code here

POST _search
 {
   "query": {
  "bool": {
     "should": [
        {
           "term": {
              "stkno": "France and Luxembourg"
           }
        },
        {
           "term": {
              "tag": "France and Luxembourg"
           }
        },
        {
           "term": {
              "context": "France and Luxembourg"
           }
        },
        {
           "term": {
              "htext": "France and Luxembourg"
           }
        }
     ],
     "minimum_should_match": 1
  }
  }
  }

谢谢...

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    here 所述,当您使用multi-matchand 运算符时,它是字段的多重匹配。所以你的查询变成了

     (+stkno:France +stkno:and +stkno:Luxembourg)
    | (+tag:France +tag:and +tag:Luxembourg)
    | (+context:France +context:and +context:Luxembourg)
    | (+htext:France +htext:and +htext:Luxembourg)
    

    对于完全匹配,您可以使用term query

    您可以将 multi-match 部分单独更改为另一个布尔查询

                            {
                                "bool": {
                                    "should": [
                                        {
                                            "term": {
                                                "stkno": "France and Luxembourg"
                                            }
                                        },
                                        {
                                            "term": {
                                                "tag": "France and Luxembourg"
                                            }
                                       },
                                        {
                                            "term": {
                                                "context": "France and Luxembourg"
                                            }
                                       },
                                        {
                                            "term": {
                                                "htext": "France and Luxembourg"
                                            }
                                        }
                                    ],
                                    "minimum_should_match": 1
                                }
                            }
    

    【讨论】:

    • 我已经尝试过你推荐的编码。但我无法得到我的结果。总点击数为 0。我从 elasticsearch 复制值,仍然找不到
    • 编码太长无法粘贴到这里
    • 编码如:POST _search { "query": { "bool": { "should": [ { (按照上面的编码) }}
    • 你能把原文件贴在问题里吗
    • 你能粘贴原始文件吗?只需使用 GET _search 并发布应该与查询匹配的文档
    猜你喜欢
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2018-01-31
    • 2020-01-25
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    相关资源
    最近更新 更多