【问题标题】:Encountering ElasticsearchIllegalArgumentException when using Phrase Suggester使用 Phrase Suggester 时遇到 ElasticsearchIllegalArgumentException
【发布时间】:2015-12-04 21:41:28
【问题描述】:

我正在尝试使用 ElasticSearch 1.7.3 为我公司的搜索引擎实现一个 Did-you-mean 功能。我按照文档设置了一个短语建议器并创建了一个自定义映射来支持它。

但是,当我执行_suggest 查询时,我得到ElasticsearchIllegalArgumentException[Suggester[simple_phrase] not supported]。我做错了什么?

这是我的查询:

POST knowledge_graph/entities/_suggest
{
  "suggest": {
    "text" : "apple in",
    "simple_phrase": {
      "phrase" : {
        "field" : "canonical_name"
      }
    }
  }
}

我收到以下回复:

{
  "_shards": {
    "total": 5,
    "successful": 0,
    "failed": 5,
    "failures": [
      {
        "index": "knowledge_graph",
        "shard": 0,
        "status": 500,
        "reason": "BroadcastShardOperationFailedException[[knowledge_graph][0] ]; nested: ElasticsearchException[failed to execute suggest]; nested: ElasticsearchIllegalArgumentException[Suggester[simple_phrase] not supported]; "
      },
      ...
    ]
  }
} 

这是我的索引的设置和映射:

{
  "knowledge_graph": {
    "aliases": {},
    "mappings": {
      "entities": {
        "properties": {
          "autocomplete": {
            "type": "completion",
            "analyzer": "simple",
            "payloads": true,
            "preserve_separators": true,
            "preserve_position_increments": true,
            "max_input_length": 50
          },
          "canonical_name": {
            "type": "string",
            "analyzer": "simple",
            "fields": {
              "shingles": {
                "type": "string",
                "analyzer": "simple_shingle_analyzer"
              }
            }
          },
          "entity_query": {
            "properties": {
              "simple_phrase": {
                "properties": {
                  "phrase": {
                    "properties": {
                      "field": {
                        "type": "string"
                      }
                    }
                  }
                }
              },
              "text": {
                "type": "string"
              }
            }
          },
          "suggest": {
            "properties": {
              "simple_phrase": {
                "properties": {
                  "phrase": {
                    "properties": {
                      "field": {
                        "type": "string"
                      }
                    }
                  }
                }
              },
              "text": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1449251691345",
        "analysis": {
          "filter": {
            "shingles_1_6": {
              "type": "shingle",
              "max_shingle_size": "6",
              "output_unigrams_if_no_shingles": "true"
            }
          },
          "analyzer": {
            "simple_shingle_analyzer": {
              "type": "custom",
              "filter": [
                "lowercase",
                "shingles_1_6"
              ],
              "tokenizer": "standard"
            }
          }
        },
        "number_of_shards": "5",
        "number_of_replicas": "0",
        "version": {
          "created": "1070399"
        },
        "uuid": "g_Yp7z6kQHCDRtd6TvVlzQ"
      }
    },
    "warmers": {}
  }
}

【问题讨论】:

    标签: elasticsearch lucene


    【解决方案1】:

    有两种方法可以执行suggest 请求,一种使用_search 端点,另一种使用_suggest 端点。

    来自Docs

    建议对 _suggest 端点执行的请求应该省略 周围的建议元素,仅在建议时使用 请求是搜索的一部分。

    如果您针对_search api 执行查询,您的查询将起作用

    POST knowledge_graph/entities/_search <---- here
    {
      "suggest": {
        "text" : "apple in",
        "simple_phrase": {
          "phrase" : {
            "field" : "canonical_name"
          }
        }
      },
       "size" : 0
    }
    

    如果你想用_suggest端点查询,试试这个

    POST knowledge_graph/_suggest
    {
      "suggest": {
        "text": "apple in",
        "phrase": {
          "field": "canonical_name"
        }
      }
    }
    

    注意 - 我认为您应该针对 canonical_name.shingles

    执行短语建议

    【讨论】:

    • 感谢您的回答,但不幸的是,我的 ElasticSearch 显然有些问题。当我对_search 端点进行查询时,我只需取回每个文档(即类似于空搜索)。当我尝试您的_suggest 查询时,我收到回复,确认我已将_id 的文档索引为_suggest
    • _search 请求中添加"size:0 以仅查看建议,并使用suggest 仅针对索引而不是类型执行请求,对此我很抱歉,请参阅我的更新答案。跨度>
    猜你喜欢
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2017-09-13
    • 1970-01-01
    • 2013-03-17
    相关资源
    最近更新 更多