如何使用DSL查询搜索所有属性?

时间:2020-08-06 15:00:36

标签: elasticsearch dsl

如何检查值是否包含字符串

下面是示例数据。我需要搜索Thomas

的任何属性
  • 您可以看到第一份文件中只有Thomas。因此,第一个文件必须返回。基本上一个文档(如果存在任何搜索字段)我需要检索该文档
   {
       "id": "Accounting 101",
       "dataproduct": "E3",
       "professor": {
           "name": "Thomas Baszo",
           "department": "finance",
           "facutly_type": "part-time",
           "email": "baszot@onuni.com"
           },
       "students_enrolled": 27,
       "course_publish_date": "2015-01-19",
       "course_description": "Act 101 is a course from the business school on the introduction to accounting that teaches students how to read and compose basic financial statements"
   }
   
   PUT /data/test/2
   {
       "name": "Accounting 101",
       "room": "E3",
       "professor": {
           "name": "Sachin Baszo",
           "department": "finance",
           "facutly_type": "part-time",
           "email": "baszot@onuni.com"
           },
       "students_enrolled": 27,
       "course_publish_date": "2015-01-19",
       "course_description": "Act 101 is a course from the business school on the introduction to accounting that teaches students how to read and compose basic financial statements"
   }

1 个答案:

答案 0 :(得分:0)

您可以使用query string搜索任何字段。

GET /_search
{
  "query": {
    "query_string": {
      "query": "Thomas"
    }
  }
}

default_field (可选,字符串)如果查询字符串中未提供任何字段,则为您要搜索的默认字段。

默认为index.query.default_field索引设置,其默认值为**值提取符合条件查询的所有字段,并过滤元数据字段。如果未指定前缀,则将所有提取的字段组合起来以构建查询。

相关问题