突出显示path_hierarchy字段

时间:2018-08-08 18:53:57

标签: elasticsearch

是否可以突出显示已被索引为path_hierarchy的字段?

{
  "settings": {
    "analysis": {
      "tokenizer": {
        "category_tokenizer": {
          "type": "path_hierarchy",
          "delimiter": ">",
          "reverse": false
        }
      },
      "analyzer": {
        "default": {
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "english_stemmer"
          ]
        },
        "case_insensitive_sort": {
          "tokenizer": "keyword",
          "filter": [
            "lowercase"
          ]
        },
        "category_analyzer": {
          "tokenizer": "category_tokenizer",
          "filter": [
            "trim",
            "hierarchy_stop"
          ]
        }
      },
      "filter": {
        "english_stemmer": {
          "type": "stemmer",
          "name": "english"
        },
        "hierarchy_stop": {
          "type":       "stop",
          "ignore_case": true,
          "stopwords":  ["category > unassigned", "unassigned"]
        }
      }
    }
  },
  "mappings": {
    "blob": {
      "properties": {
        "sys_blob": {
          "type": "binary",
          "store": true,
          "doc_values": false
        },
        "sys_itemid": {
          "type": "keyword"
        },
        "sys_meta": {
          "type": "keyword",
          "index": false,
          "store": true,
          "doc_values": false
        }
      }
    },
    "clob": {
      "properties": {
        "sys_clob": {
          "type": "keyword",
          "index": false,
          "store": true,
          "doc_values": false
        },
        "sys_itemid": {
          "type": "keyword"
        },
        "sys_meta": {
          "type": "keyword",
          "index": false,
          "store": true,
          "doc_values": false
        }
      }
    },
    "item": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "sort": {
              "type": "keyword"
            }
          },
          "index_options" : "offsets"
        },
        "fileid": {
          "type": "keyword"
        },
        "description": {
          "type": "text",
          "index_options" : "offsets"
        }
      },
      "dynamic_templates": [

        {
          "_cat": {
            "match": "*_cat",
            "mapping": {
              "type": "string",
              "fielddata": true,
              "analyzer": "category_analyzer",
              "search_analyzer": "category_analyzer"
            }
          }
        },
        {
          "_hier": {
            "match": "*_hier",
            "mapping": {
              "type": "string",
              "fielddata": true,
              "analyzer": "hierarchy_analyzer",
              "search_analyzer": "hierarchy_analyzer"
            }
          }
        }
      ]
    }
  }
}

和一个示例查询。高亮显示keyword_s和标题字段。

{
  "query": {
    "simple_query_string": {
      "query": "\"Surface Water\"  ",
      "fields": [
        "title^5",
        "categories_cat^20",
        "description",
        "keywords_s",
        "_all"
      ],
      "default_operator": "and"
    }
  },
  "highlight": {
    "require_field_match": false,
    "pre_tags": [
      "<em>"
    ],
    "post_tags": [
      "</em>"
    ],
    "fields": {
      "title": {
        "require_field_match": false
      },
      "categories_cat": {
        "require_field_match": false
      }
    }
  }
}

0 个答案:

没有答案