问题:
I am using query_string to search for records from Elastic,
Example Query :
GET /stories_qa/_search
{
"query": {
"query_string": {
"query": "Johnson &&...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I am using query_string
to search for records from Elastic,
Example Query :
GET /stories_qa/_search
{
"query": {
"query_string": {
"query": "Johnson && Johnson"
}
}
}
This query gives me relevant records, but the exact match record is not on top, I figured out on how we can boost records based on specific fields, but in my case, I don't want to provide field and make search restrictive, Is there an option in ElasticSearch to achieve the same.
回答1:
You can probably do something like below, but do thorough testing and test multiple scenarios before you move it to production.
POST <your_index_name>/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"query_string": {
"query": ""Karnataka Delhi"",
"default_operator": "AND"
}
}
]
}
},
{
"query_string": {
"query": "Karnataka Delhi",
"default_operator": "OR",
"boost": 2
}
},
{
"query_string": {
"query": "Karnataka Delhi",
"default_operator": "AND",
"boost": 4
}
}
]
}
}
}
Hope this helps!
回答2:
It would help with examples, but you can use phrase_match
query by adding double quote. If you add a boost to the phrase_match
query you will be able to get to exact match ranked higher.
The following query should do what you want.
GET /stories_qa/_search
{
"query": {
"query_string": {
"query": "("Johnson && Johnson")^2 OR (Johnson && Johnson)"
}
}
}