2017-05-24 43 views
0

此使用是一个代码Elasticsearch含义必须multimatch

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分的记录。但其中一个确切地说'法国和卢森堡',另外一个'法国'。

我的问题如下:

  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 
    } 
    } 
    } 

感谢...

回答

0

如前所述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

我已经试过您的建议编码..但我不能让我的结果。总命中数为0。我将复制elasticsearch值时,它仍然无法找到 –

+0

编码太长,我不能在这里 –

+0

贴上编码,如:POST _search { “查询”:{ “布尔”:{ “应“:[ {请按照上面的代码进行编码)}} –

相关问题