Reputation: 97
I have 3 types with the same fields names indexed in Elasticsearch 5:
TypeA
integer id
string name
TypeB
integer id
string name
TypeC - integer id - string name
GET myindex/TypeA,TypeB,TypeC/_search
{
"_source": ["id", "name"],
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [
"_all",
"name^3"
],
"query": "Foo bar*",
"default_operator": "and"
}
}
]
}
}
}
I only want to boost the name field for TypeA. In this scenario the name field for TypeA, TypeB and TypeC are boosted.
How can I only boost the name for TypeA?
I'm looking for something like this:
"fields": [
"_all",
"TypeA.name^3"
]
Thank You.
Upvotes: 0
Views: 108
Reputation: 217554
You need to create one subquery for type A and another subquery for types B and C
GET myindex/_search
{
"_source": [
"id",
"name"
],
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"_type": "TypeA"
}
},
{
"query_string": {
"fields": [
"_all",
"name^3"
],
"query": "Foo baar*",
"default_operator": "and"
}
}
]
}
},
{
"bool": {
"must": [
{
"terms": {
"_type": [
"TypeB",
"TypeC"
]
}
},
{
"query_string": {
"fields": [
"_all",
"name"
],
"query": "Foo baar*",
"default_operator": "and"
}
}
]
}
}
]
}
}
}
Upvotes: 1