elasticsearch 类似于此搜索无法在列表对象中字段上工作

hivapdat  于 2022-11-22  发布在  ElasticSearch
关注(0)|答案(1)|浏览(136)

这是我的索引的Map我正在搜索的有效负载嵌套字段类别

{
   "mappings": {
      "date_detection": false,
      "properties": {
         "@class": {
            "type": "keyword"
         },       
         "id": {
            "type": "text",
            "fields": {
               "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
               }
            }
         },
         "payload": {
            "type": "nested",
            "properties": {
               "@class": {
                  "type": "keyword"
               },
             
                     "description": {
                        "type": "text",
                        "fields": {
                           "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                           }
                        }
                     },
                     
                    
                     "title": {
                        "type": "text",
                        "fields": {
                           "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                           }
                        }
                     }
                  }
               },
               "category": {
                  "type": "keyword"
               },
              
               "value": {
                  "type": "text",
                  "fields": {
                     "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                     }
                  }
               }
            }
         }
      }
   }
}

这是我的索引Map,每当我尝试在elasticsearch中搜索与此查询类似的对象时,它不会返回任何对象,

**我正在搜索对象列表
**查询是

{
  "query": {
    "more_like_this": {
      "fields": [
        "payload.category"
      ],
      "like": [
        "ASSEST"
      ],
    
      "min_term_freq": 1,
      "max_query_terms": 12
    }
  }
}

它不返回任何对象,但值存在于ElasticSearch中
我只是想搜索类似的对象值存在于ElasticSearch更彻底像这样的查询
但有效负载实际上是一个有字段类别的对象列表,我需要根据它来查找相似的对象

w9apscun

w9apscun1#

对于嵌套字段,使用nested query

GET <index-name>/_search
{
  "query": {
    "nested": {
      "path": "payload",
      "query": {
        "more_like_this": {
          "fields": [
            "payload.category"
          ],
          "like": [
            "assest doc"
          ],
          "min_term_freq": 1,
          "max_query_terms": 12
        }
      }
    }
  }
}

还要查找min_doc_freq
最小文档频率,低于该频率的术语将从输入文档中忽略。默认值为5。
如果匹配文档少于5个,请将“min_doc_freq”设置为1

相关问题