我想通过搜索在Elasticsearch中只显示一条记录



使用以下查询:

GET feeds/_search
{
"query": {
"nested": {
"path": "comment",
"query": {
"multi_match": {
"query": "ali",
"fields": ["body","title","comment.c_text"]
}
}
}
}
}

我正在得到结果

{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.8025915,
"hits" : [
{
"_index" : "feeds",
"_type" : "_doc",
"_id" : "NeoTNIUB1Qg_7rFp-8RV",
"_score" : 0.8025915,
"_source" : {
"feed_id" : "1",
"title" : "Mateen",
"body" : "This is mateen",
"comment" : [
{
"c_id" : "11",
"feed_id" : "1",
"c_text" : "get well soon mateen"
},
{
"c_id" : "12",
"feed_id" : "1",
"c_text" : " Ali here"
}
]
}
}
]
}
}

我不想看到我的第一个记录,因为它不包含"ali"在身体,标题,comment_text。有人能帮忙吗?如果它在搜索"ali"它会返回提要id标题体,评论id提要id和c_text但不显示数组的内容不包含ali隐藏它

{
"c_id" : "11",
"feed_id" : "1",
"c_text" : "get well soon mateen"
}

我不想在我的输出中看到这个内容

首先,像这样更新映射:

POST feeds/_mapping
{
"properties": {
"title": {
"type": "text",
"analyzer": "lowercase"
},
"body": {
"type": "text",
"analyzer": "lowercase"
},
"comment": {
"type": "nested",
"properties": {
"c_text": {
"type": "text",
"analyzer": "lowercase"
}
}
}
}
}

然后运行这个查询

{
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "ali",
"analyzer": "lowercase"
}
}
},
{
"match": {
"body": {
"query": "ali",
"analyzer": "lowercase"
}
}
},
{
"nested": {
"path": "comment",
"query": {
"match": {
"comment.c_text": {
"query": "ali",
"analyzer": "lowercase"
}
}
}
}
}
]
}
}
}
GET feeds/_search
{
"query": {
"bool": {
"should": [
{
"nested": {
"path": "comment",
"query": { 
"match": {
"comment.c_text": "hey"
}
},"inner_hits": {
"highlight": {
"require_field_match": "true"

}
}
}
},
{
"term": {
"title": {
"value": "hey"
}
}
},
{
"term": {
"body": {
"value": "hey"
}
}
}
]
}
}
}
通过这种方式,我们可以通过内部点击 获得结果。

相关内容

最新更新