gpt4 book ai didi

elasticsearch - 如何按类型过滤建议查询

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

假设我已经映射了多种类型,例如CompanyCustomer。这些类型与建议字段映射。当我对这两种类型执行suggest查询时,一切正常。现在,我想限制查询以查找一种类型的结果。我阅读了有关上下文建议程序的here。这也可以,但是现在我找不到这两种类型,因为我必须设置上下文。将上下文保留为空不会返回任何结果。如何削减高迪氏结?除了使用Context Suggester之外,还有其他方法吗?

这是我对Company的映射(略有缩短):

 "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"
]
}
}
}
}
}

最佳答案

能够通过上下文提示器实现它。我将上下文中的path设置为_type

例:

1)映射

put test/company/_mapping
{
"company": {

"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"
}
}
}
}
}
}

put test/customer/_mapping
{
"customer": {

"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"
}
}
}
}
}
}

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"]
}
}
}
}

关于elasticsearch - 如何按类型过滤建议查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33127771/

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