Py学习  »  Elasticsearch

ElasticSearch-突出显示“.keyword”和文本字段

M Nikesh • 4 年前 • 409 次点击  

在使用完整数据搜索字段时,我发现了突出显示的问题。我使用了自定义分析器,每个字段都存储为文本和关键字。

我使用空白作为搜索分析器。

我的自定义分析器是:

"analysis": {
  "filter": {
    "indexFilter": {
      "type": "pattern_capture",
      "preserve_original": "true",
      "patterns": [
        "([@,$,%,&,!,.,#,^,*]+)",
        "([\\w,.]+)",
        "([\\w,@]+)",
        "([-]+)",
        "(\\w+)"
      ]
    }
  },
  "analyzer": {
    "indexAnalyzer": {
      "filter": [
        "indexFilter",
        "lowercase"
      ],
      "tokenizer": "whitespace"
    },
    "searchAnalyzer": {
      "filter": [
        "lowercase"
      ],
    "tokenizer": "whitespace"
  }
}

我的映射文件是:

"field": {
  "type": "text",
  "term_vector": "with_positions_offsets",
  "fields": {
    "keyword": {
      "type": "keyword",
      "ignore_above": 256
    }
  },
  "analyzer": "indexAnalyzer",
  "search_analyzer": "searchAnalyzer"
}

我的问题是:

{
  "from": 0,
  "size": 24,
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "monkey business",
            "type": "phrase",
            "slop": "2",
            "fields": []
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "highlight": {
    "type": "unified",
    "fields": {
      "*": {}
    }
  }
}

我的亮点是:

"highlight": {
  "field.keyword": [
    "<em>monkey business</em>"
  ],
  "field": [
    "<em>monkey</em> <em>business</em>"
  ]
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40019
 
409 次点击  
文章 [ 1 ]  |  最新文章 4 年前