首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Elasticsearch中使用暗示一词?

如何在Elasticsearch中使用暗示一词?
EN

Stack Overflow用户
提问于 2015-09-11 07:01:50
回答 1查看 1.7K关注 0票数 1

我想使用ElasticSearch1.7中的暗示词组。

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html

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

嵌套:ElasticsearchIllegalArgumentException[没有为字段项目名找到映射];

代码语言:javascript
复制
$ curl -XPOST 'localhost:9200/_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]是明确定义的。

实际上,我可以使用这个查询从itemname字段中搜索。

代码语言:javascript
复制
$ 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"}
    }, {

在这种情况下我怎么了?

有人建议我如何正确地使用暗示一词吗?

谢谢。

添加我的设置

代码语言:javascript
复制
# 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"
          }
        }
      }
    },
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-11 08:29:15

我认为,由于您在根端点/上运行建议程序查询,您的搜索会碰到另一个索引,该索引没有定义itemname字段的任何映射类型。

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

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

代码语言:javascript
复制
                        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
      }
    }
  }
}'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32517470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档