ElasticSearch“匹配”几个词?

时间:2019-10-08 16:55:14

标签: elasticsearch

我做了一个布尔查询:

...
"bool":{
   "should" : [
    {"match": {"Process.Name": "eu.customers" }},
    {"regexp": {"Process.Name": ".*customers_all" }}
  ]
}
...

我也许发现match子句中的空格可以用OR ???解释

所以我会得到与:相同的结果

...
{"match": {"Process.Name": "eu.customers customers_all" }}
...

如果是的话,我认为文档很差

2 个答案:

答案 0 :(得分:0)

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

有点模棱两可,但提示是:

  

如果您需要知道bool查询中的哪些子句与   查询返回的文档,可以使用命名查询进行分配   每个子句的名称。

我认为您要么需要看看:

  1. “必须”条款
  2. 使用https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html限定“应”项

答案 1 :(得分:0)

我做了一些测试,并且match子句按您期望的那样工作。

match cluase

PUT t2


PUT t2/_doc/1
{
  "Process.name":"eu.customers"
}

PUT t2/_doc/2
{
  "Process.name":"customers_all"
}

GET t2/_search
{
  "query": {
    "match": {
      "Process.name": "eu.customers customers_all"
    }
  }
}

输出:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.6931472,
    "hits" : [
      {
        "_index" : "t2",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.6931472,
        "_source" : {
          "Process.name" : "eu.customers"
        }
      },
      {
        "_index" : "t2",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.6931472,
        "_source" : {
          "Process.name" : "customers_all"
        }
      }
    ]
  }
}

我怀疑您在Process.name字段上的分析器正在以匹配查询不匹配的方式创建倒排索引。尝试分析该字段,看看如何创建倒排索引。

GET indexname/_analyze
{
  "field": "Process.name",
  "text": ["eu.customers"]
}

GET indexname/_analyze
{
  "field": "Process.name",
  "text": ["customers_all"]
}