【问题标题】:elastic search highlight not working with filter query弹性搜索突出显示不适用于过滤器查询
【发布时间】:2015-11-12 03:20:17
【问题描述】:

这辈子都无法突出这一点。似乎弹性搜索在突出显示过滤子句中提到的字段方面被破坏了。下面的查询只是没有突出显示。这是 Elastic 的问题吗?我可以做些什么来完成这项工作?

    {
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "language": "Austrian"
              }
            }
          ]
        }
      },
      "filter": {
        "and": [
          {
            "query": {
              "query_string": {
                "fields": [
                  "standard_analyzed_name",
                  "standard_analyzed_message"
                ],
                "query": "Arnold AND Schwarz"
              }
            }
          }
        ]
      }
    }
  },
  "size": 20,
  "sort": [
    {
      "total_interactions": {
        "order": "desc"
      }
    }
  ],
  "highlight": {
    "fields": {
      "standard_analyzed_name": {
        "pre_tags": [
          "<strong>"
        ],
        "post_tags": [
          "</strong>"
        ],
        "fragment_size": 500,
        "number_of_fragments": 1
      },
      "standard_analyzed_message": {
        "pre_tags": [
          "<strong>"
        ],
        "post_tags": [
          "</strong>"
        ],
        "fragment_size": 500,
        "number_of_fragments": 1
      }
    }
  }
}

更新

上述查询确实在弹性搜索 2.0.0 中突出显示 - Yayyy

【问题讨论】:

标签: elasticsearch elasticsearch-plugin


【解决方案1】:

嗯,简单地说,你的queryfilter 部分交换了。你的query_string 应该进入query 部分,term 应该进入filter 部分,然后一切都会好起来,你会看到突出显示的字段。

{
   "query": {
      "filtered": {
         "query": {
            "query_string": {
               "fields": [
                  "standard_analyzed_name",
                  "standard_analyzed_message"
               ],
               "query": "arnold"
            }
         },
         "filter": {
            "term": {
               "language": "austrian"
            }
         }
      }
   },
   "size": 20,
   "sort": [
      {
         "total_interactions": {
            "order": "desc"
         }
      }
   ],
   "highlight": {
      "fields": {
         "standard_analyzed_name": {
            "pre_tags": [
               "<strong>"
            ],
            "post_tags": [
               "</strong>"
            ],
            "fragment_size": 500,
            "number_of_fragments": 3
         },
         "standard_analyzed_message": {
            "pre_tags": [
               "<strong>"
            ],
            "post_tags": [
               "</strong>"
            ],
            "fragment_size": 500,
            "number_of_fragments": 3
         }
      }
   }
}

【讨论】:

  • 谢谢,但我的查询应该仍然有效。高光似乎有点挑剔..你能详细说明一下吗?
  • 不返回任何数据。
  • arnoldaustrian 都是小写的,我确实得到了一个结果和一个突出显示的字段:"I like &lt;strong&gt;Arnold&lt;/strong&gt;"
  • 我修改了我的查询。注意query": "Arnold AND Schwarz。使用 and 关键字。这是我为弹性编写的 API 的结果。这个查询条件对你还有效吗?
  • 如果我没记错的话,你之前分享的关于阿诺德的文档中没有Schwarz
猜你喜欢
  • 2019-02-19
  • 1970-01-01
  • 2019-12-17
  • 1970-01-01
  • 1970-01-01
  • 2015-01-25
  • 1970-01-01
  • 1970-01-01
  • 2017-07-02
相关资源
最近更新 更多