Reputation: 51
{
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"query": "template testing",
"fields": [
"tag^8.0",
"title^10.0",
"body^3.0"
],
"flags": -1,
"default_operator": "or",
"analyze_wildcard": false,
"auto_generate_synonyms_phrase_query": false,
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"fuzzy_transpositions": true,
"boost": 1
}
},
],
"filter": [
{
"terms": {
"assetCourse.assetType": [
"epub"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"sort": { "_score": { "order": "desc" }}
}
I want to search for the exact keyword 'template testing' first then tokenized search with 'template' and 'testing' but with my query it only search for 'template' and 'testing' seperately. please help me improve the query.
Upvotes: 0
Views: 368
Reputation: 87
Just do a simple match query which will order the results with both terms occurring at the top followed by results with individual terms. You can add other params using this link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
{
"query": {
"bool": {
"should": [
{
"match": {
"tag": {
"query": "template testing"
}
}
},
{
"match": {
"title": {
"query": "template testing"
}
}
},
{
"match": {
"body": {
"query": "template testing"
}
}
}
]
}
}
}
Upvotes: 1