elasticsearch - Elastic Multimatch Query与文档不匹配

标签 elasticsearch boolean match analyzer

我正在使用以下查询在 flex (v6.7)中查询与短语“x射线”匹配的项目:

POST item/_search
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "type": "phrase_prefix",
          "query": "X-Ray",
          "fields": [
            "mpn", 
            "product_description"
            "manufacturer_name"
          ], 
          "operator": "and",
          "analyzer": "standard"
        }
      }
    }
  }
}

结果集为空。

我有包含短语“x射线”的项目文档。例如,如果我查询:
GET items/_doc/3e4a2d80-9d5e-11e7-a6c5-6ddf18575461

它返回:
{
    "_index": "items",
    "_type": "_doc",
    "_id": "3e4a2d80-9d5e-11e7-a6c5-6ddf18575461",
    "_version": 1,
    "_seq_no": 7605,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "manufacturer_name": "GE",
        "var_pricing": 0,
        "on_hand": 1,


        ...

        "product_description": "Portable X-Ray w/Fuji CR Reader", <----This should be a match!
        "project_id": null,
        "user_id": "12",
        "quote_items": [],
        "parentCategory": [
            0
        ]
    }
}

如果我在新安装的elastic(v7.3)版本上运行查询,则在其中添加三个文档,如下所示:
POST product/_bulk
{"index":{"_id":1001}}
{"name":"x-ray Machine","price":152000,"in_stock":38,"sold":47,"tags":["Alcohol","Wine"],"description":"x-ray machine for x-rays","is_active":true,"created":"2004\/05\/13"}
{"index":{"_id":1002}}
{"name":"X-Ray film","price":99,"in_stock":10,"sold":430,"tags":[],"description":"just some x-ray film","is_active":true,"created":"2007\/10\/14"}
{"index":{"_id":1003}}
{"name":"Table","price":2500,"in_stock":24,"sold":215,"tags":[],"description":"could be used for an x-ray table","is_active":true,"created":"2000\/11\/17"}

然后查询:
POST product/_search
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "type": "phrase_prefix",
          "query": "X-Ray",
          "fields": [
            "name", 
            "description"
          ], 
          "operator": "and",
          "analyzer": "standard"
        }
      }
    }
  }
}

返回所有三个项目:
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : 31.876595,
    "hits" : [
      {
        "_index" : "product",
        "_type" : "default",
        "_id" : "1001",
        "_score" : 31.876595,
        "_source" : {
          "name" : "x-ray Machine",
          "price" : 152000,
          "in_stock" : 38,
          "sold" : 47,
          "tags" : [
            "Alcohol",
            "Wine"
          ],
          "description" : "x-ray machine for x-rays",
          "is_active" : true,
          "created" : "2004/05/13"
        }
      },
      {
        "_index" : "product",
        "_type" : "default",
        "_id" : "1002",
        "_score" : 27.347116,
        "_source" : {
          "name" : "X-Ray film",
          "price" : 99,
          "in_stock" : 10,
          "sold" : 430,
          "tags" : [ ],
          "description" : "just some x-ray film",
          "is_active" : true,
          "created" : "2007/10/14"
        }
      },
      {
        "_index" : "product",
        "_type" : "default",
        "_id" : "1003",
        "_score" : 25.889376,
        "_source" : {
          "name" : "Table",
          "price" : 2500,
          "in_stock" : 24,
          "sold" : 215,
          "tags" : [ ],
          "description" : "could be used for an x-ray table",
          "is_active" : true,
          "created" : "2000/11/17"
        }
      }
    ]
  }
}

是什么赋予了?

我使用了explain API来获得更多的见解,但它说明没有匹配项:
POST items/_doc/3e4a2d80-9d5e-11e7-a6c5-6ddf18575461/_explain
{
  "query": {
    "bool": {
      "must": [
        {
            "multi_match": {
              "type": "phrase_prefix",
              "query": "X-Ray",
              "fields": [
                "product_description",
                "mpn",
                "manufacturer_name"
              ], 
              "operator": "and",
              "analyzer": "standard"
        }}
        ]
      }
    }
  }
}

返回值:
{
    "_index": "items",
    "_type": "_doc",
    "_id": "3e4a2d80-9d5e-11e7-a6c5-6ddf18575461",
    "matched": false,
    "explanation": {
        "value": 0,
        "description": "Failure to meet condition(s) of required/prohibited clause(s)",
        "details": [
            {
                "value": 0,
                "description": "no match on required clause (((+product_description:x +product_description:ray) | (+mpn:x +mpn:ray) | (+manufacturer_name:x +manufacturer_name:ray)))",
                "details": [
                    {
                        "value": 0,
                        "description": "No matching clause",
                        "details": []
                    }
                ]
            },
            {
                "value": 0,
                "description": "no match on required clause (MatchNoDocsQuery(\"Type list does not contain the index type\"))",
                "details": [
                    {
                        "value": 0,
                        "description": "MatchNoDocsQuery(\"Type list does not contain the index type\") doesn't match id 12556",
                        "details": []
                    }
                ]
            }
        ]
    }
}

当我将分析器更改为空白或关键字时,变化不大。

最佳答案

(这不是答案,但我无法在注释中输入所有内容)

如果您打算整体匹配analyzer,我不确定您是否真的需要在查询中使用X-Ray

看这个

POST _analyze
{
  "analyzer": "standard", 
  "text":"X-Ray"
}

响应是
{
  "tokens" : [
    {
      "token" : "x",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "ray",
      "start_offset" : 2,
      "end_offset" : 5,
      "type" : "<ALPHANUM>",
      "position" : 1
    }
  ]
}

因此您的搜索词X-Ray变为xray。这是您想要的吗?

关于elasticsearch - Elastic Multimatch Query与文档不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57332679/

相关文章:

null - 如何在Elasticsearch结果中允许空值?

performance - 匹配整数文字集

elasticsearch - Elasticsearch:结合功能分数

search - 如何提高Elasticsearch中的搜索相关性顺序?

java - Elasticsearch JEST 日期序列化 java

spring - 使用 Spring 数据在 Elasticsearch 存储库中执行多面搜索?

R匹配2个以上条件并返回响应值

matlab - 测试表 Matlab 中是否存在列

python - 查找一个数据帧的哪些行存在于另一个数据帧中

python - 如何使用 pandas 返回 boolean 值比较组中的项目?