gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中使用短语提示器?

转载 作者:行者123 更新时间:2023-12-02 23:34:59 25 4
gpt4 key购买 nike

我想在Elasticsearch 1.7中使用词组建议程序。

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

因此,我在下面的查询中创建了类似“待办页面”示例,但出现了错误。

nested: ElasticsearchIllegalArgumentException[No mapping found for field [itemname]];


$ 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字段中搜索。
$ 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"}
}, {

在这种情况下我怎么了?
有人建议我如何正确使用短语提示器吗?

谢谢。

添加我的设置
# 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"
}
}
}
},

最佳答案

我认为,由于您正在根端点/上运行建议程序查询,因此您的搜索将找到另一个索引,该索引没有任何定义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
}
}
}
}'

关于elasticsearch - 如何在Elasticsearch中使用短语提示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32517470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com