gpt4 book ai didi

elasticsearch - 在Elasticsearch v2.3.5中与multi_match查询一起过滤

转载 作者:行者123 更新时间:2023-12-02 22:59:32 28 4
gpt4 key购买 nike

我是Elasticsearch和Nest的新手,请原谅我的无知。我想在Elasticsearch v2.3.5中将过滤器与multi_match查询一起使用,但到目前为止我还无法弄清楚。我认为,一旦将其用于Elasticsearch,我就应该能够将其映射到Nest。

以下是我的JSON数据结构:

{
"contentID":1,
"categoryID":0,
"title":"...",
"description":"...",
"contentHtml":"...",
"version":2,
"parentContentID":0,
"displayOrder":0,
"freshdeskID":0,
"isDraft":false,
"isCommentingEnabled":false,
"isArticle":false,
"grandParentContentID":0,
"isAnyParentDraft":false
}

以下是我的有效搜索查询(没有任何过滤器):
POST contents/supportitem/_search?pretty=true
{
"size": 150,
"highlight": {
"fields": {
"contentHtml": {
"fragment_size": 245
}
}
},
"_source": {
"include": [
"title",
"contentID",
"description",
"thumbnailUrl",
"isDraft",
"isAnyParentDraft",
"grandParentContentID"
]
},"query": {
"multi_match": {
"type": "cross_fields",
"query": "query typed by user",
"tie_breaker": 0.3,
"fields": [
"title^1.1",
"additionalContents^1.2",
"contentHtml^1"
]
}
}
}

我只想向用户显示搜索结果中的那些记录:
grandParentContentID != 0 and
isDraft != false and
isAnyParentDraft != false

我尝试了可能不同的查询,但无法弄清楚该如何写。

几个不起作用的查询,包括:
POST contents/supportitem/_search?pretty=true
{
"size": 150,
"highlight": {
"fields": {
"contentHtml": {
"fragment_size": 245
}
}
},
"_source": {
"include": [
"title",
"contentID",
"description",
"thumbnailUrl",
"isDraft",
"isAnyParentDraft",
"grandParentContentID"
]
},"query": {
"multi_match": {
"type": "cross_fields",
"query": "Tile map server resources",
"tie_breaker": 0.3,
"fields": [
"title^1.1",
"additionalContents^1.2",
"contentHtml^1"
]
},"filtered": {
"filter": {
"bool": {
"term": {
"isAnyParentDraft": "false"
}
}
}
}
}
}


POST contents/supportitem/_search?pretty=true
{
"size": 150,
"highlight": {
"fields": {
"contentHtml": {
"fragment_size": 245
}
}
},
"_source": {
"include": [
"title",
"contentID",
"description",
"thumbnailUrl",
"isDraft",
"isAnyParentDraft",
"grandParentContentID"
]
},"query": {
"multi_match": {
"type": "cross_fields",
"query": "Tile map server resources",
"tie_breaker": 0.3,
"fields": [
"title^1.1",
"additionalContents^1.2",
"contentHtml^1"
]
},"filtered": {
"query": {
"bool": {
"must": [
{
"field": {"isAnyParentDraft": "false"}
}
]
}
}
}
}
}

我得到 "failed to parse search source. expected field name but got [START_OBJECT]"
我可以正常工作,但无法弄清楚如何添加更多过滤器:
POST contents/supportitem/_search?pretty=true
{
"size": 150,
"highlight": {
"fields": {
"contentHtml": {
"fragment_size": 245
}
}
},
"_source": {
"include": [
"title",
"contentID",
"description",
"thumbnailUrl",
"isDraft",
"isAnyParentDraft",
"grandParentContentID"
]
},
"query": {
"filtered": {
"query": {
"multi_match": {
"type": "cross_fields",
"query": "deleted",
"tie_breaker": 0.3,
"fields": [
"title^1.1",
"additionalContents^1.2",
"contentHtml^1"
]
}
},
"filter": {
"and": {
"filters": [
{
"term": {
"isAnyParentDraft": "false"
}
}
]
}
}
}
}
}

我提到了以下问题:

ElasticSearch with multi_match AND bool-仅具有一个过滤器

Elasticsearch: multi_match no effect with filters

最佳答案

很好的开始,您快要完成了:

POST contents/supportitem/_search?pretty=true
{
"size": 150,
"highlight": {
"fields": {
"contentHtml": {
"fragment_size": 245
}
}
},
"_source": {
"include": [
"title",
"contentID",
"description",
"thumbnailUrl",
"isDraft",
"isAnyParentDraft",
"grandParentContentID"
]
},
"query": {
"bool": {
"must": {
"multi_match": {
"type": "cross_fields",
"query": "deleted",
"tie_breaker": 0.3,
"fields": [
"title^1.1",
"additionalContents^1.2",
"contentHtml^1"
]
}
},
"must_not": [
{
"term": {
"isAnyParentDraft": "false"
}
},
{
"term": {
"isDraft": "false"
}
},
{
"term": {
"grandParentContentID": 0
}
}
]
}
}
}

关于elasticsearch - 在Elasticsearch v2.3.5中与multi_match查询一起过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38962257/

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