希望在Elasticsearch中搜索词的一部分的功能不返回任何内容。仅适用于完整的单词

问题描述 投票:0回答:1

我尝试了两种不同的创建索引的方法,如果我搜索单词的一部分,都将返回任何内容。基本上,如果我搜索单词的首字母或中间字母,则需要获取所有文档。

通过创建索引(other stackoverflow question a bit old)的第一个尝试:

POST correntistas/correntista
{
  "index": {
    "index": "correntistas",
    "type": "correntista",
    "analysis": {
      "index_analyzer": {
        "my_index_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "mynGram"
          ]
        }
      },
      "search_analyzer": {
        "my_search_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "mynGram"
          ]
        }
      },
      "filter": {
        "mynGram": {
          "type": "nGram",
          "min_gram": 2,
          "max_gram": 50
        }
      }
    }
  }
}

通过创建索引的第二种方法(other recent stackoverflow question

PUT /correntistas
{
    "settings": {
        "analysis": {
            "filter": {
                "autocomplete_filter": {
                    "type": "edge_ngram",
                    "min_gram": 1,
                    "max_gram": 20
                }
            },
            "analyzer": {
                "autocomplete_search": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase"
                    ]
                },
                "autocomplete_index": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "autocomplete_filter"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "nome": {
                "type": "text",
                "analyzer": "autocomplete_index",
                "search_analyzer": "autocomplete_search"
            }
        }
    }
}

[这第二个尝试失败,并带有

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters:  [nome : {search_analyzer=autocomplete_search, analyzer=autocomplete_index, type=text}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [properties]: Root mapping definition has unsupported parameters:  [nome : {search_analyzer=autocomplete_search, analyzer=autocomplete_index, type=text}]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "Root mapping definition has unsupported parameters:  [nome : {search_analyzer=autocomplete_search, analyzer=autocomplete_index, type=text}]"
    }
  },
  "status": 400
}

Kibana Print Screen

尽管我创建索引的第一种方法是无一例外创建索引,但是当我键入部分属性“ nome”时,它不起作用。

我以此方式添加了一个文档

POST /correntistas/correntista/1
    {
        "conta": "1234",
        "sobrenome": "Carvalho1",
        "nome": "Demetrio1"
    }

现在,我想通过键入第一个字母(例如De)或键入中间单词的一部分(例如met)来检索上述文档。但是,我正在搜索的以下两种方式均未检索文档

简单查询方式:

GET correntistas/correntista/_search
{
    "query": {
        "match": {
            "nome": {
                "query": "De" #### "met" should I also work from my perspective
            }
        }
    }
}

更详细的查询方式也会失败

GET correntistas/correntista/_search
{
    "query": {
        "match": {
            "nome": {
                "query": "De",  #### "met" should I also work from my perspective
                "operator": "OR",
                "prefix_length": 0,
                "max_expansions": 50,
                "fuzzy_transpositions": true,
                "lenient": false,
                "zero_terms_query": "NONE",
                "auto_generate_synonyms_phrase_query": true,
                "boost": 1
            }
        }
    }
}

我认为不相关,但是这里是版本(我正在使用此版本,因为它旨在用于使用spring-data的生产环境,并且在Spring-data中添加Elasticsearch的新版本存在一些“延迟”)] >

elasticsearch and kibana 6.8.4

PS .:请不要建议我不要使用正则表达式,也不要使用通配符(*)。

我尝试了两种不同的创建索引的方法,如果我搜索单词的一部分,都将返回任何内容。基本上,如果我搜索单词的首字母或中间字母,... ...>

elasticsearch kibana spring-data-elasticsearch elasticsearch-aggregation elasticsearch-analyzers
1个回答
0
投票

在我的this SO answer中,要求是一种前缀搜索,即对于文本Demetrio1仅搜索所需的de demet,它与我创建edge-ngram tokenizer来解决这个问题一样,但是在这个问题中,< [需要提供中缀搜索

,我们将在自定义分析器中使用ngram tokenizer
© www.soinside.com 2019 - 2024. All rights reserved.