![](/img/trans.png)
[英]I want to use ElasticSearch 6 or ElasticSearch 7 for searching
[英]I want to display only one record in Elasticsearch by searching
使用以下查詢:
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”。 誰能幫忙? 我希望如果它正在搜索“ali”,那么它將返回 feed id title body 以及評論 id feed 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"
}
}
}
]
}
}
}
這樣我們就可以通過內部命中得到結果
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.