如何使用 DSL 查询搜索所有属性?
How to search in all attributes using DSL query?
如何检查值是否包含字符串
以下是示例数据。我需要搜索 Thomas
的任何属性
- 你可以看到我在第一个文档中只有 Thomas。所以第一个文档必须 return。基本上一个文档,如果存在任何搜索字段,我需要检索该文档
{
"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"
}
您可以使用 query string 在任何字段上进行搜索。
GET /_search
{
"query": {
"query_string": {
"query": "Thomas"
}
}
}
default_field
(Optional, string) Default field you wish to search if no field is provided in the query string.
默认为 index.query.default_field
索引设置,其默认值为 *
。 *
值提取所有符合术语查询条件的字段并过滤元数据字段。如果未指定前缀,则所有提取的字段将组合起来构建查询。
如何检查值是否包含字符串
以下是示例数据。我需要搜索 Thomas
- 你可以看到我在第一个文档中只有 Thomas。所以第一个文档必须 return。基本上一个文档,如果存在任何搜索字段,我需要检索该文档
{
"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"
}
您可以使用 query string 在任何字段上进行搜索。
GET /_search
{
"query": {
"query_string": {
"query": "Thomas"
}
}
}
default_field (Optional, string) Default field you wish to search if no field is provided in the query string.
默认为 index.query.default_field
索引设置,其默认值为 *
。 *
值提取所有符合术语查询条件的字段并过滤元数据字段。如果未指定前缀,则所有提取的字段将组合起来构建查询。