query = query.Filter(elastic.NewScriptQuery(elastic.NewScript("doc['val1'].value == doc['val2'].value")))
Elasticsearch查询使用Go Olivere / elastic过滤value1 == value2的文档
I need to build query to get documents where doc.value1 == doc.value2
{
"query": {
"bool" : {
"filter" : [{
"script" : {
"script" : {
"source": "doc['val1'].value == doc['val2'].value",
"lang": "painless"
}
}
}]
}
}
}
This what I need to build with olivere/elastic, it work if I send it as POST request.
In golang I have something like
"github.com/olivere/elastic"
...
query := elastic.NewBoolQuery()
// then add something to this query or leave it empty it works fine
// but if I add
query = query.Filter(elastic.NewBoolQuery().Must(elastic.NewScript("doc.['val1'].value == doc.['val2'].value")))
// I'm getting: Error 400 (Bad Request): [source] query malformed,
// no start_object after query name [type=parsing_exception]
// Then i run it like:
client, err := elastic.NewClient()
if err != nil {
fmt.Println(err)
return
}
resp, err := client.Search("myIndex").Type("myDoc").Query(query).TrackTotalHits(true).Size(limit).Do(context.Background())
if err != nil {
fmt.Println(err)
return
}
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
1条回答
为你推荐
- Java程序向elasticsearch服务器发出搜索请求
- Elasticsearch-field_value_factor,缺少参数
- elasticsearch
- python
- 2个回答
- 从golang服务器到ES的ES查询返回错误,而直接向ES的邮递员请求则返回预期结果
- elasticsearch
- 1个回答
- Golang:如何为Elasticsearch管道附件构建结构
- elasticsearch
- 2个回答
- Elasticsearch查询使用Go Olivere / elastic过滤value1 == value2的文档
- elasticsearch
- 1个回答
- Symfony Elastic Bundle错误
- 多个指标Elasticsearch上的相同聚合
- elasticsearch
- php
- 1个回答
- Elasticsearch多个术语/过滤器
- elasticsearch
- php
- 1个回答
- 使用PHP API为Elasticsearch设置not_analyzed字段
- elasticsearch
- php
- 1个回答
- Elasticsearch - 与不同客户的不同结果
- elasticsearch
- php
- curl
- 1个回答
- 在过滤器中包含“NULL”值以及Elastica中的范围过滤器
- elasticsearch
- php
- 1个回答
- 动态弹性搜索查询
- elasticsearch
- php
- 1个回答
- Elasticsearch PHP致命错误:未捕获的TypeError:参数1
- elasticsearch
- php
- 1个回答
- Elasticsearch中[GeoDistanceSort]的非法纬度值
- elasticsearch
- php
- 1个回答
- PHP期望[END_OBJECT]但得到[FIELD_NAME],可能有太多查询子句
- elasticsearch
- php
- 1个回答
- ElasticSearch按嵌套字段值排序
- Elasticsearch首先根据值排序
- elasticsearch
- sorting
- php
- mysql
- 1个回答
- 从多个条件的Elasticsearch获取数据
- elasticsearch
- php
- 1个回答
- Elasticsearch如何使用通配符进行OR查询
- elasticsearch
- php
- 1个回答
- elasticsearch 如何批量删除重复数据?
- elasticsearch
- 数据
- 4个回答