Hello,
I'm implementing the new search engine on my website and I have doubts about my code.
The following code (working version) it's quite bulky and can be bigger depending on search term and I think that it could be optimized. My example is based on search terms: "nabla chair". As you can see for each term must clause contain a block of should clause code with one of the terms. If I search using terms: "nabla long chair" one more should block of code will be added and so on.
GET proitems/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"nested": {
"path": "name",
"query": {
"bool": {
"minimum_should_match": 1,
"filter": {
"terms": {
"name.lng": [
"en",
"de"
]
}
},
"should": [
{
"term": {
"name.text": "nabla"
}
},
{
"term": {
"name.text.folded": "nabla"
}
}
]
}
}
}
},
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"man_name": "nabla"
}
},
{
"term": {
"man_name.folded": "nabla"
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "name",
"query": {
"bool": {
"minimum_should_match": 1,
"filter": {
"terms": {
"name.lng": [
"en",
"de"
]
}
},
"should": [
{
"term": {
"name.text": "chair"
}
},
{
"term": {
"name.text.folded": "chair"
}
}
]
}
}
}
},
{
"bool": {
"minimum_should_match": 1,
"should": [
{
"term": {
"man_name": "chair"
}
},
{
"term": {
"man_name.folded": "chair"
}
}
]
}
}
]
}
}
]
}
}
}
Any suggestion would be welcome in order to optimize the code.
Thanks