elasticsearch 如何按类型筛选建议查询
假设我已经映射了多种类型,如elasticsearch 如何按类型筛选建议查询,elasticsearch,nest,elasticsearch,Nest,假设我已经映射了多种类型,如公司和客户。这些类型映射为建议字段。当我对这两种类型执行suggest查询时,一切都正常。现在我想将查询限制为查找一种类型的结果。我读到了上下文提示。这也是可行的,但现在我找不到这两种类型,因为我必须设置上下文。将上下文保留为空不会返回任何结果。如何解决棘手的问题?是否有一种不同于使用上下文提示器的方法 这是我为公司所做的(略为缩短的)映射: "company": { "dynamic": "false", "_id": { "path
公司
和客户
。这些类型映射为建议字段。当我对这两种类型执行suggest
查询时,一切都正常。现在我想将查询限制为查找一种类型的结果。我读到了上下文提示。这也是可行的,但现在我找不到这两种类型,因为我必须设置上下文。将上下文保留为空不会返回任何结果。如何解决棘手的问题?是否有一种不同于使用上下文提示器的方法
这是我为公司
所做的(略为缩短的)映射:
"company": {
"dynamic": "false",
"_id": {
"path": "Id"
},
"properties": {
"name": {
"type": "string"
},
"suggest": {
"type": "completion",
"analyzer": "simple",
"payloads": true,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"context": {
"type": {
"type": "category",
"path": "type",
"default": [
"company"
]
}
}
}
}
}
能够通过上下文提示实现它。我将上下文中的
路径设置为\u type
例如:
1) 映射
2) 示例文件
PUT test/company/1
{
"name": "hello company",
"suggest": {
"input": ["hello", "hello company"]
}
}
PUT test/customer/1
{
"name": "hello customer",
"suggest": {
"input": ["hello again", "hello customer"]
}
}
3) 建议:类型公司
POST test/_suggest
{
"suggest" : {
"text" : "hel",
"completion" : {
"field" : "suggest",
"size": 10,
"context": {
"type": ["customer"]
}
}
}
}
4) 建议:输入客户
post test/_suggest
{
"suggest" : {
"text" : "hel",
"completion" : {
"field" : "suggest",
"size": 10,
"context": {
"type": ["company"]
}
}
}
}
5) 建议:输入公司和客户
post test/_suggest
{
"suggest" : {
"text" : "hel",
"completion" : {
"field" : "suggest",
"size": 10,
"context": {
"type": ["company","customer"]
}
}
}
}
工作起来很有魅力!事实上,我也以类似的方式尝试过,使用Nest
(一个C#client)但没有成功。我想有点小错误,我会再试一次。非常感谢您抽出时间!
post test/_suggest
{
"suggest" : {
"text" : "hel",
"completion" : {
"field" : "suggest",
"size": 10,
"context": {
"type": ["company","customer"]
}
}
}
}