0

我在弹性搜索中遇到了这个我无法解释的问题。有时会出现突出显示,但有时不会出现。以下是通过 kibana 重现它的方法。我的索引和映射 -

PUT test_index
{
  "mappings": {
    "doc": {
      "properties": {
        "type": {
          "type": "text"
        },
        "packages": {
          "type": "nested",
          "include_in_root": true,
          "properties": {
            "amount": {
              "type": "keyword",
              "fields": {
                "raw": { 
                  "type": "double" 
                }
              }
            },
            "rem_amount": {
              "type": "keyword",
              "fields": {
                "raw": { 
                  "type": "double" 
                }
              }
            }
          }
        }
      }
    }
  }
}

插入样本数据

PUT test_index/doc/1
{
  "id": 1,
  "type": "data",
  "packages" : [
    {
      "amount": "100.0",
      "rem_amount": "100.5"
    }
  ]
}

以下查询(查询 1 和查询 2)不返回突出显示。请注意我有一个更大的查询。我在这里只粘贴其中的一部分。

查询 1:require_field_match: truefields: ["packages.*"]。输出 - 没有突出显示

GET test_index/_search
{
  "query": {
    "query_string": {
      "query": "100",
      "fields": ["packages.*"],
      "type":"phrase_prefix"
    }
  },
  "min_score": 0.000001,
  "highlight" : {
    "require_field_match": true,
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
}

查询 2:require_field_match: falsefields: ["packages.*"]。输出 - 没有突出显示

GET test_index/_search
{
  "query": {
    "query_string": {
      "query": "100",
      "fields": ["packages.*"],
      "type":"phrase_prefix"
    }
  },
  "min_score": 0.000001,
  "highlight" : {
    "require_field_match": false,
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
}

仅在require_field_match : false和 I REMOVE line "fields": ["packages.*"]是亮点出现的情况下:查询 3

GET test_index/_search
{
  "query": {
    "query_string": {
      "query": "100",
      "type":"phrase_prefix"
    }
  },
  "min_score": 0.000001,
  "highlight" : {
    "require_field_match": false,
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
}

突出显示的块:

"highlight": {
          "packages.rem_amount": [
            "<em>100.5</em>"
          ],
          "packages.amount": [
            "<em>100.0</em>"
          ]
        }

谁能解释一下这种行为?将 require_field_match 设置为 false 也应该返回查询 2 中的突出显示。“字段”列和“require_field_match”以什么方式影响这种行为?

4

0 回答 0