如何提升match\u all elasticsearch领域

ldxq2e6h  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(551)

我需要找更多的权重给教授
然后下一个获得权重的属性是professor.email
下面检查搜索字符串所在的其他字段是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"
 }

下面是查询
获取/\u搜索 {"from" : 0, "size" : 100,"query": {"match_all": {}}}) 如何实施 "fields": [ "professor.name^16", "professor.email^8"]

brvekthn

brvekthn1#

您可以使用匹配查询上的多字段匹配查询生成来允许多字段查询:
搜索查询:

{
  "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"
        }
      }
    ]

相关问题