elasticsearch - 在 _source 结果集中包含附加值
问题描述
我正在尝试查看是否可以在运行时根据查询更新 _source 结果集中的字段,下面是查询:
body = {
"from": 0,
"size": 5,
"_source": ["*"],
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"query_string": {
"query": "home visit*",
"fields": [
"name",
"procedures"
],
"boost": 1
}
},
{
"script": {
"script": {
"source": "if (doc['policy_types_keyword'].size() != 0) { return true; } else { return false; }",
"lang": "painless"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"query_string": {
"query": "home visit*",
"fields": [
"name",
"keywords",
"specialties"
],
"boost": 1
}
},
{
"script": {
"script": {
"source": "if (doc['policy_types_keyword'].size() != 0) { return true; } else { return false; }",
"lang": "painless"
}
}
}
]
}
}
],
"minimum_should_match": 1
}
}
]
}
}
}
如果结果来自 must 子句的第一部分,则 _source 应将 'procedures' 更新为 True
"procedures": True
如果结果来自 must 子句的第二部分,则 _source 应包含“specialties”
"specialties": True
如果结果来自 must 的两个部分
"procedures": True
"specialties": True
基本上,我试图在结果集中添加一个字段,让客户知道结果行来自过程查询或专业查询,或两者兼而有之。有没有办法做到这一点?
解决方案
推荐阅读
- c++ - if 语句中的赋值 - 输出如何正确?
- python - Scrapy 和 selenium - 单独使用 selenium 时有效,但不适用于 scrapy
- python - 我想将一个包导入我的项目目录中的另一个包
- asynchronous - 如何从事件循环函数中获取返回
- jax-rs - 在 JAX-RS Web 服务/Maven/Eclipse/Tomcat 9 上出现 404 错误
- javascript - textarea 不根据内容扩展
- java - Spring Mockito Mocked 对象不断调用真实方法
- sql-server - 未从查询中获取任何行,但表中有可用行
- javascript - 删除数组中的前导零
- docker - Docker + MariaDB 给我 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)