我的文件如下
[
{'id':1, 'name': 'sachin messi', 'description': 'football@football.com', 'type': 'football', 'var':'sports'},
{'id':2, 'name': 'lionel messi', 'description': 'messi@fifa.com','type': 'soccer','var':'sports'},
{'id':3, 'name': 'sachin', 'description': 'was', 'type': 'cricket', 'var':'sports'}
]
DSL查询如下
{
"query": {
"bool": {
"must": [
{
"terms": {
"var.keyword": [
"sports"
]
}
},
{
"match_phrase_prefix": {
"name": {
"query": "lio"
}
},
"highlight": {
"fields": {
"name": {}
}
}
}
]
}
}
}
获取误差
RequestError: RequestError(400,“x_content_parse_exception”,“match_phrase_prefix格式错误查询,预期的END_OBJECT但找到了FIELD_NAME”)
我的期望只有身份证:2
发布于 2022-07-12 00:05:01
突出显示and应该是外部查询子句,而不是内部查询。
{
"query": {
"bool": {
"must": [
{
"terms": {
"var.keyword": [
"sports"
]
}
},
{
"match_phrase_prefix": {
"name": {
"query": "lio"
}
}
}
]
}
},
"highlight": {
"fields": {
"name":{}
}
}
}
发布于 2022-07-12 00:03:46
您已经快到了,但是您需要在JSON中将highlight
与query
并行,而不是在query
中。正确的查询将是
{
"query": {
"bool": {
"must": [
{
"terms": {
"var.keyword": [
"sports"
]
}
},
{
"match_phrase_prefix": {
"name": {
"query": "lio"
}
}
}
]
}
},
"highlight": {
"fields": {
"name": {}
}
}
}
https://stackoverflow.com/questions/72948852
复制