elasticsearch 如何在Elasticsearch中使用短语Suggester?,elasticsearch,elasticsearch" /> elasticsearch 如何在Elasticsearch中使用短语Suggester?,elasticsearch,elasticsearch" />

elasticsearch 如何在Elasticsearch中使用短语Suggester?

elasticsearch 如何在Elasticsearch中使用短语Suggester?,elasticsearch,elasticsearch,我想在Elasticsearch 1.7中使用短语Suggester 所以,我创建了下面的查询,比如doDocumentPages示例,但我得到了错误 嵌套:ElasticsearchIllegalArgumentException[未找到的映射] 字段[itemname]] 但是字段[itemname]]是明确定义的。 事实上,我可以使用此查询从itemname字段进行搜索 $ curl -XPOST 'localhost:9200/_search?pretty' -d '{ "quer

我想在Elasticsearch 1.7中使用短语Suggester

所以,我创建了下面的查询,比如doDocumentPages示例,但我得到了错误

嵌套:ElasticsearchIllegalArgumentException[未找到的映射] 字段[itemname]]

但是字段[itemname]]是明确定义的。
事实上,我可以使用此查询从itemname字段进行搜索

$ curl -XPOST 'localhost:9200/_search?pretty' -d '{
  "query": {
    "function_score": {
      "query": {
        "filtered": {
          "query": {
            "query_string": {
              "fields": [
                "itemname"
              ],
              "query": "cola"
            }
          }
        }
      }
    }
  }
}'
{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 15,
    "successful" : 15,
    "failed" : 0
  },
  "hits" : {
    "total" : 97,
    "max_score" : 11.625176,
    "hits" : [ {
      "_index" : "my_index",
      "_type" : "my_type",
      "_id" : "20615",
      "_score" : 11.625176,
      "_source":{"itemid":"20615","itemname":"cola 500ml"}
    }, {
在这种情况下,我怎么了?
有人建议我如何正确使用Suggester这个短语吗

谢谢

添加我的设置

# curl -XGET 'http://localhost:9200/my_index?pretty'
{
  "my_index" : {
    "aliases" : { },
    "mappings" : {
      "my_type" : {
        "_all" : {
          "enabled" : true,
          "analyzer" : "kuromoji_analyzer"
        },
        "properties" : {
          "itemid" : {
            "type" : "string",
            "index" : "not_analyzed",
            "store" : true
          },
          "catname" : {
            "type" : "string",
            "store" : true,
            "analyzer" : "kuromoji_analyzer"
          },
          "itemname" : {
            "type" : "string",
            "store" : true,
            "analyzer" : "kuromoji_analyzer"
          },
          "myscore" : {
            "type" : "double",
            "store" : true
          },
          "subcatname" : {
            "type" : "string",
            "store" : true,
            "analyzer" : "kuromoji_analyzer"
          }
        }
      }
    },

我认为,由于您正在根端点
/
上运行suggester查询,因此您的搜索会命中另一个索引,该索引没有定义
itemname
字段的任何映射类型

尝试直接在具有定义
itemname
字段的映射类型的索引上运行查询

根据第二次查询的结果,您应该尝试在
/my_index/my_type
而不是根端点
/
上运行建议程序

                        add the index and the type
                                |      |
                                v      v
curl -XPOST 'localhost:9200/my_index/my_type/_search?pretty' -d '{
  "query": {
    "function_score": {
      "query": {
        "filtered": {
          "query": {
            "query_string": {
              "fields": [
                "itemname"
              ],
              "query": "cola"
            }
          }
        }
      }
    }
  },
  "suggest": {
    "text": "cola",
    "simple_phrase": {
      "phrase": {
        "field": "itemname",
        "size": 5,
        "real_word_error_likelihood": 0.95,
        "max_errors": 0.5,
        "gram_size": 2
      }
    }
  }
}'

您是否可能在一个索引中定义了几种不同的类型(因为您正在根目录下搜索
/
),而其中一种没有
itemname
字段?@Val感谢您的回复。是的,实际上就像你说的,我有两个索引。另一个指标是完成建议。我把我的设置添加到帖子中。有没有错误的设置?此外,我还尝试将“itemname”添加到“my_index_suggest”设置并运行短语建议查询,但我遇到了相同的错误。您在哪个索引上运行建议器?它没有出现在您的问题中(即顶部的第一个查询)@Val oh,“curl-XPOST'localhost:9200/my_index/my_type/_search?pretty”正在工作。是的,因为
itemname
是在
my_type
中定义的。那好
                        add the index and the type
                                |      |
                                v      v
curl -XPOST 'localhost:9200/my_index/my_type/_search?pretty' -d '{
  "query": {
    "function_score": {
      "query": {
        "filtered": {
          "query": {
            "query_string": {
              "fields": [
                "itemname"
              ],
              "query": "cola"
            }
          }
        }
      }
    }
  },
  "suggest": {
    "text": "cola",
    "simple_phrase": {
      "phrase": {
        "field": "itemname",
        "size": 5,
        "real_word_error_likelihood": 0.95,
        "max_errors": 0.5,
        "gram_size": 2
      }
    }
  }
}'