![](/img/trans.png)
[英]How to convert Lucene query string to Elasticsearch Match/Match_Prefix etc equivalent
[英]How to apply term query with match_prefix in elasticsearch
我的文件在下面
[
{'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]')
我的預期結果只有 id:2
您快到了,但您需要在 JSON 中與query
並行highlight
,而不是在query
中。 正確的查詢是
{
"query": {
"bool": {
"must": [
{
"terms": {
"var.keyword": [
"sports"
]
}
},
{
"match_phrase_prefix": {
"name": {
"query": "lio"
}
}
}
]
}
},
"highlight": {
"fields": {
"name": {}
}
}
}
突出顯示應該在查詢子句之外,而不是在查詢內。
{
"query": {
"bool": {
"must": [
{
"terms": {
"var.keyword": [
"sports"
]
}
},
{
"match_phrase_prefix": {
"name": {
"query": "lio"
}
}
}
]
}
},
"highlight": {
"fields": {
"name":{}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.