首页 文章

Elasticsearch突出显示:使用“copy_to”创建的自定义“_all”字段的“多匹配”查询

提问于
浏览
0

(Elasticsearch 5.2.2)

我在突出显示正常工作时遇到了一些麻烦 . 我的映射有2个自定义创建的_all-fields myall1myall2 ,它们是通过 copy_to 创建的:

"mytype": {
  "_all": {
    "enabled": false
  },
  "properties": {
    "myall": {
        "type": "text",
        "analyzer": "standard",
        "store": true
    },
    "myall2": {
        "type": "text",
        "analyzer": "standard",
        "store": true
    },
    "field1": {
        "type": "text",
        "copy_to": "myall1",
        "analyzer": "keyword"
    },
    "field2": {
        "type": "text",
        "copy_to": "myall2",
        "analyzer": "keyword"
    }
}

文档看起来像这样:

{
  "field1": "example text",
  "field2": "another text"
}

现在我正在运行 multi_match -query,将 myall1 提升3:

POST /myindex/mytype/_search
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "fields": ["myall1^3", "myall2"],
          "type": "cross_fields",
          "query": "example text",
          "operator": "and"
        }
      }
    }
  }
}

这非常有效 . 问题是我无法突出显示结果中的原始源字段 . 我在查询中添加以下内容的方式与在ES-docs _1075061中完成的方式相同:

,
  "highlight": {
    "pre_tags": ["<span class='highlight'>"],
    "post_tags": ["</span>"],
    "fields": {
      "*": {"require_field_match": false}
    }
  }

这只给了我在“myall1”和“myall2”中的突出显示,而不是在原始字段“field1”和“field2”中 .

如果我使用_all-field做类似的事情,一切都按预期工作 . 主要区别在于:我使用multi_match,而示例使用query_string . 玩"store":true和"analyzer":"standard"没有帮助 .

由于我的实际文档使用必须可搜索的嵌套对象,因此我可能无法执行完全不同的查询方法 .

这是设计还是我错过了什么?使用“_all”-field不允许我按照我试图实现它的方式来提高结果 .

1 回答

  • 0

    固定它 . 似乎突出显示原始字段要求他们使用与“复制到”目标字段相同的分析器 . 否则他们根本就不会出现 .

    之前我使用的是“analyzer”:“keyword”,因为我不打算对这些字段进行实际查询 . 现在一切都按预期工作 .

相关问题