【发布时间】:2016-08-15 20:06:01
【问题描述】:
我是 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