我想利用query_string查询的功能,但我需要查询默认在字段子集(不是全部,但也不仅仅是一个)中进行搜索。当我尝试传递许多默认字段时,查询失败。有什么建议么?
没有在查询中指定特定字段,所以我想默认搜索三个字段:
{
"query": {
"query_string" : {
"query" : "some search using advanced operators OR dog",
"default_field": ["Title", "Description", "DesiredOutcomeDescription"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果您想对上述 3 个特定字段创建查询,只需使用该fields参数即可。
{
"query": {
"query_string" : {
"query" : "some search using advanced operators OR dog",
"fields": ["Title", "Description", "DesiredOutcomeDescription"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您想默认搜索这 3 个字段而不指定它们,则必须copy_to在设置映射时使用该参数。然后将默认字段设置为串联字段。
PUT my_index
{
"settings": {
"index.query.default_field": "full_name"
},
"mappings": {
"my_type": {
"properties": {
"first_name": {
"type": "text",
"copy_to": "full_name"
},
"last_name": {
"type": "text",
"copy_to": "full_name"
},
"full_name": {
"type": "text"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经使用过它,但不推荐它,因为对标记化的控制可能受到限制,因为您只能为连接字段指定一个标记生成器。
这是 copy_to 上的页面。
| 归档时间: |
|
| 查看次数: |
3594 次 |
| 最近记录: |