【问题标题】:The different custom analyzers for index and search in Elasticsearch giving NULL results for user queriesElasticsearch 中用于索引和搜索的不同自定义分析器为用户查询提供 NULL 结果
【发布时间】:2020-12-01 10:35:57
【问题描述】:

在这段代码中,我为索引时间和搜索时间定义了两个不同的自定义分析器,在映射字段中,我还指定了“分析器”和“搜索分析器”。

PUT /demo
{
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "synonym_test":{
            "type":"synonym",
            "synonyms_path":"analysis/output.txt"
          },
          "english_stop":{
            "type":"stop",
            "stopwords":"_english_"
        },
          "en_US":{
            "type":"hunspell",
            "language":"en_US"
        }
        },
        "analyzer": {
          "autocomplete": {
            "filter": [
              "lowercase",
              "synonym_test",
              "english_stop",
              "en_US"
            ],
            "type":"custom",
            "tokenizer": "standard"
          },
          "complete":{
            "filter": [
              "lowercase",
              "english_stop",
              "en_US"
            ],
            "type":"custom",
            "tokenizer": "standard"
          }
        }
      }
    }
  },
 "mappings": {
  "properties": {
    "Content":{
        "type": "text",
        "analyzer": "autocomplete",
        "search_analyzer": "complete"
      },
    "query":{
      "type":"percolator"
    }
    }
  }
}

我使用analyze api检查了上述查询。

GET demo/_analyze
{
  "text": "fractured"
  , "analyzer": "autocomplete"
}

它正在显示令牌:

{
  "tokens" : [
    {
      "token" : "fracture",
      "start_offset" : 0,
      "end_offset" : 9,
      "type" : "<ALPHANUM>",
      "position" : 0
    }
  ]
}

也在运行中:

GET demo/_analyze
{
  "text": "fractured"
  , "analyzer": "complete"
}

它正在显示令牌:

{
  "tokens" : [
    {
      "token" : "fracture",
      "start_offset" : 0,
      "end_offset" : 9,
      "type" : "<ALPHANUM>",
      "position" : 0
    }
  ]
}

我有一个演示:

PUT demo/_doc/1
{
"Content":"fracture foot"
}

但是当我将搜索查询写成:

GET demo/_search
{
    "query": {
        "match": {
            "Content": {
                "query": "fracture"
            }
        }
    }
}

或者如果我写:

GET demo/_search
{
    "query": {
        "match": {
            "Content": {
                "query": "fractured"
            }
        }
    }
}

对于这两个查询,我都得到空结果。 请帮我解决这个问题。 en_US 是 Hunspell 词典词干分析器,我还添加了同义词过滤器。 请帮帮我。

【问题讨论】:

  • 在索引期间使用同义词过滤器而不在搜索期间使用同义词过滤器是否会产生问题?如果是,那么为什么使用搜索 API 会产生问题?
  • 你能提供与fracture相关的同义词列表吗?
  • 骨折 => 断裂,分裂,破裂,破碎

标签: elasticsearch search kibana analyzer


【解决方案1】:

问题已解决,我只是将同义词文件中的同义词从“fracture => break, split, nucleus, broken”更改为“fracture,break, split,rupture, broken”,现在所有的词都被索引了.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    相关资源
    最近更新 更多