elasticsearch - 如何在完整的字典中搜索
问题描述
{'name':'abc','description':{'value':'abc','test':124}}
我在上面有一个 DSL 查询。我的关键“描述”是一组字典,以下查询是否正确
{
"from":0,
"size":1000,
"query":{
"bool":{
"must":{
"query_string":{
"query":"Pencil",
"fields":[
"name^8",
"description^2"
]
}
}
}
}
}
如果我想在字典上搜索特定关键字,那么我可以这样做description.value.keyword
解决方案
如果未提供任何字段,则 multi_match 查询默认为 index.query.default_field 索引设置,而后者又默认为 *。它提取映射中符合术语查询的所有字段并过滤元数据字段。然后组合所有提取的字段以构建查询。
如果要搜索and字段中的所有属性,可以使用多匹配查询name
description
添加具有索引数据、映射、搜索查询和搜索结果的工作示例
指数数据:
{
"name": "abc",
"description": {
"value": "abc",
"test": 124
}
}
{
"name": "John",
"description": {
"value": "abc",
"test": 124
}
}
搜索查询:
{
"query": {
"multi_match" : {
"query": "abc"
}
}
}
搜索结果:
"hits": [
{
"_index": "65824093",
"_type": "_doc",
"_id": "1",
"_score": 0.6931471,
"_source": {
"name": "abc",
"description": {
"value": "abc",
"test": 124
}
}
},
{
"_index": "65824093",
"_type": "_doc",
"_id": "2",
"_score": 0.18232156,
"_source": {
"name": "John",
"description": {
"value": "abc",
"test": 124
}
}
}
]
如果您想知道所有字段中哪个字段匹配,那么您可以使用突出显示
推荐阅读
- json - 如何将 Pandas 数据输出到 JSON,并在数组中包含特定列
- c# - MVVM 中的可见性转换器未更新
- sql - Oracle SQL:根据多行条件拆分组
- django - 保存后获取模型字段
- docker - 如何在 docker 构建过程中使用环境变量获取脚本?
- image - 使用一组 TImage 来查找特定的 Image
- javascript - 更新集群中的功能后如何更新地图?
- php - PHPunit Drupal8:“节点”实体类型不存在
- spring - 如何使用 Spring 设置不同的安全级别
- python - 如何在 Windows 上使用多个进程为 Flask 应用程序提供服务