Elastic Search Lowercase 分析器不返回搜索结果

发布于 2025-01-11 04:48:49 字数 1146 浏览 0 评论 0原文

我有一个基于文本的索引,如下所示。我试图根据用户输入的标记来维护精确搜索和模糊搜索。虽然基于文本的搜索工作正常(部分搜索),但当涉及术语搜索时,它会返回数据,前提是大小写相同。 我确实尝试添加基于小写过滤器的分析器,但它没有帮助。我在这里能做什么?

映射:

"project_title": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },
  "projectabstract": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },

基于小写分析器的新索引:

PUT /project_term_search_text_analyzer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "rebuilt_standard": {
          "tokenizer": "standard",
          "filter": [
            "lowercase"       
          ]
        }
      }
    }
  },
  "mappings": {"project_title": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },
  "projectabstract": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },}

我应该如何更新索引以在这两种情况下工作。

I have a text based index like below. I am trying to maintain both exact search and ambiguous search based on tokens based on user input. While text based search works fine(partial search) when it comes to term search it returns data iff case is the same.
I did try adding a lowercase filter based analyzer but it does not help. What can I do here?

Mappings:

"project_title": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },
  "projectabstract": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },

New index based on lowercase analyzer:

PUT /project_term_search_text_analyzer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "rebuilt_standard": {
          "tokenizer": "standard",
          "filter": [
            "lowercase"       
          ]
        }
      }
    }
  },
  "mappings": {"project_title": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },
  "projectabstract": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },}

How should I update my index to work in both cases.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁 2025-01-18 04:48:49

您需要使用适用于关键字字段。您还可以自定义规范化器(如分析器),在链接中您可以找到带有小写过滤器的相关示例,这将解决您的问题。

You need to use the normalizer which works on the keyword fields. You can also customize your normalizer like analyzer, In the link you can find the relevant example with lowercase filter, which would solve your issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文