弹性搜索突出显示不使用自定义分析器/标记器

时间:2017-09-27 15:00:55

标签: elasticsearch

我无法弄清楚为什么突出显示不起作用。查询有效,但突出显示只显示没有em标签的字段内容。这是我的设置和映射:

PUT wmsearch
{
  "settings": {
    "index.mapping.total_fields.limit": 2000,
    "analysis": {
      "analyzer": {
        "custom": {
          "type": "custom",
          "tokenizer": "custom_token",
          "filter": [
            "lowercase"
          ]
        },
        "custom2": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": [
            "lowercase"
          ]
        }
      },
      "tokenizer": {
        "custom_token": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 10
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "document": {
          "properties": {
            "reference": {
              "type": "text",
              "analyzer": "custom"
            }
          }
        },
        "scope" : {
          "type" : "nested",
          "properties" : {
            "level" : { 
              "type" : "integer"
            },
            "ancestors" : { 
              "type" : "keyword",
              "index" : "true"
            },
            "value" : { 
              "type" : "keyword",
              "index" : "true"
            },
            "order" : {
              "type" : "integer"
            }    
          }
        }
      }
    }
  }
}

这是我的问题:

GET wmsearch/_search
{
  "query": {
    "simple_query_string" : { 
      "fields": ["document.reference"],
      "analyzer": "custom2",
      "query" : "bloom"
    } 
  },
  "highlight" : {
    "fields" : {
      "document.reference" : {}
    }
  }
}

查询确实返回了正确的结果,并且结果中存在突出显示字段。但是,“bloom”周围没有em标签。相反,它只显示整个字符串,根本没有标记。

有人在这里看到任何问题或者可以提供帮助吗?

由于

1 个答案:

答案 0 :(得分:0)

我通过在document.reference的映射中添加“index_options”:“offsets”来实现它。

相关问题