如何在match_all elasticsearch中增加字段 [英] How to boost the field in match_all elasticsearch

查看:160
本文介绍了如何在match_all elasticsearch中增加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我需要搜索更多有关教授的名称。

  • I need to search more weightage to professor.name

然后选择下一个属性权重为Professor.email

Then next attribute to get the weightage is professor.email

检查搜索字符串是否存在的其他字段
以下是elasticsearch中的示例数据

The check the other fields where search string is there Below is the sample data in elasticsearch

 PUT /data/test/1
{
     "id": "Accounting 101",
     "room": "E3",
     "professor": {
         "name": "Thomas Baszo",
         "email": "baszot@onuni.com"
         },
     "students_enrolled": 27,
     "course_description": " financial statements"
 }

 PUT /data/test/2
 {
     "name": "Accounting 101",
     "room": "E3",
     "professor": {
         "name": "Sachin Baszo",
         "email": "baszot@onuni.com"
         },
     "students_enrolled": 27, 
     "course_description": "Thomas  Thomas Thomas Thomas "
 }

 PUT /data/test/3
 {
     "name": "Accounting 101",
     "room": "E3",
     "professor": {
         "name": "Sachin Baszo",
         "email": "Thomas@onuni.com"
         },
     "students_enrolled": 27, 
     "course_description": "Nothing"
 }



下面是查询

GET / _search

GET /_search

{ from :0,大小 :100, query:{ match_all:{}}})

如何实现 fields :[[ professor.name ^ 16, professor.email ^ 8]

推荐答案

您可以使用 multi_match查询建立在匹配查询的基础上,以允许多字段查询:

You can use the multi_match query build on the match query to allow multi-field queries:

搜索查询:

{
  "query": {
    "multi_match" : {
      "query" : "thomas",
      "fields" : [ "professor.name^16", "professor.email^8"]
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "stof_64275333",
        "_type": "_doc",
        "_id": "1",
        "_score": 15.693266,
        "_source": {
          "id": "Accounting 101",
          "room": "E3",
          "professor": {
            "name": "Thomas Baszo",
            "email": "baszot@onuni.com"
          },
          "students_enrolled": 27,
          "course_description": " financial statements"
        }
      },
      {
        "_index": "stof_64275333",
        "_type": "_doc",
        "_id": "3",
        "_score": 7.846633,
        "_source": {
          "name": "Accounting 101",
          "room": "E3",
          "professor": {
            "name": "Sachin Baszo",
            "email": "Thomas@onuni.com"
          },
          "students_enrolled": 27,
          "course_description": "Nothing"
        }
      }
    ]

这篇关于如何在match_all elasticsearch中增加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆