elasticsearch - 带空格的 Elasticsearch 术语不返回任何结果
问题描述
无论大小写如何,我都想匹配确切的文本。我想要的作品
GET elastic_org/_search
{
"query": {
"match": {
"registeredName": {
"minimum_should_match": "100%",
"query": "prop org"
}
}
}
}
但是我使用的库https://github.com/olivere/elastic/不支持最低应该匹配
我正在尝试term
查询
GET elastic_org/_search
{
"query": {
"term": {
"registeredName": "Prop org" //also tried prop org
}
}
}
我没有得到任何结果。我尝试了上面的查询,nospace
得到了结果。
如何在不区分大小写和空格的情况下获得精确匹配?
索引映射:
{
"elastic_org" : {
"mappings" : {
"properties" : {
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"registeredName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
解决方案
您可以将case_insensitive
参数与术语查询一起使用。这个参数是在 elasticsearch 7.10.0 版本中引入的
{
"query": {
"term": {
"registeredName.keyword": {
"value": "prop org",
"case_insensitive": true
}
}
}
}
更新1:
术语查询返回与搜索词完全匹配的文档。使用术语查询时,text
不应使用类型字段。
根据您的索引映射,您需要将 .keyword 添加到该registeredName
字段。这使用关键字分析器而不是标准分析器(注意字段后的“.keyword” registeredName
)。
更新 2:
如果不想使用case_insensitive
参数,可以使用小写过滤器。这将确保在索引和搜索之前所有术语都是小写的
添加带有索引数据、映射、搜索查询和搜索结果的工作示例
索引映射:
{
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"properties": {
"registeredName": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
}
}
指数数据:
{
"registeredName": "Prop org"
}
搜索查询:
{
"query": {
"term": {
"registeredName": "prop org"
}
}
}
搜索结果:
"hits": [
{
"_index": "67716203",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"registeredName": "Prop org"
}
}
]
推荐阅读
- python - Dask 分布式确保新工作人员获取由 upload_file 上传的模块
- installation - 用于 Linux 的 Windows 子系统上的 Rust 安装失败:无法重命名组件文件
- java - JHipster Spring boot:org.hibernate.HibernateException:无法访问 lob 流
- ruby-on-rails - 不允许的参数:has_many 中的办公室:通过 Rails 5 中的关联
- apache-spark - 使用 Spark 结构化流的流标准化
- java - 数组动态初始化后无法识别
- javascript - 无法在 Javascript 中定义正确的 RegEx
- python - 计算距离度量后的返回索引
- javascript - SweetAlert2 关闭后滚动到初始元素
- javascript - for循环不循环代码多次JS