简体   繁体   English

从 output 中删除查询短语,用于词干查询弹性搜索

[英]Remove query phrase from output for stemming query elastic search

I just started with elastic search.我刚开始使用弹性搜索。 it is working properly for everything but I want stemming result not contains search phrase它适用于所有内容,但我希望词干结果不包含搜索短语

example if I search consult then I got result consult , consultant So I want only consultant例如如果我搜索咨询然后我得到结果咨询顾问所以我只想要顾问

 "filter": {
    "my_stemmer": {
      "type": "stemmer",
      "language": "light_german"
    }
  }

Can I change type: stemmer..?我可以更改类型:词干分析器..吗?

One way to achieve your required use case is to use multi fields.实现所需用例的一种方法是使用多字段。

Adding a working example with index data, mapping, search query, and search result添加具有索引数据、映射、搜索查询和搜索结果的工作示例

Index Mapping:索引映射:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "stemmer"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "my_analyzer",
        "fields": {
          "exact": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

Index Data:指数数据:

{
    "content":"consult"
}
{
    "content":"consultant"
}

Search Query:搜索查询:

{
  "query": {
    "bool": {
      "must": {
        "match": {
          "content": "consult"
        }
      },
      "must_not": {
        "match": {
          "content.exact": "consult"
        }
      }
    }
  }
}

Search Result:搜索结果:

"hits": [
      {
        "_index": "65701139",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.18232156,
        "_source": {
          "content": "consultant"
        }
      }
    ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM