Boosting sku.exact (not_analyzed) not returning expected results


(Zelfapp) #1

When searching on my sku.exact field, if there is an exact match I want that item to always be listed first. I'm missing something in my query to boost the sku.exact matching.

Essential Parts of my Mapping:

{
   "mymap.v1": {
      "mappings": {
         "mymap": {
            "_all": {
               "enabled": false
            },
            "properties": {
               "sbb": {
                  "type": "boolean"
               },
               "sku": {
                  "type": "string",
                  "analyzer": "full_name",
                  "fields": {
                     "exact": {
                        "type": "string",
                        "index": "not_analyzed"
                     },
                     "partial": {
                        "type": "string",
                        "index_analyzer": "partial_name",
                        "search_analyzer": "full_name"
                     }
                  }
               },
               "tags": {
                  "type": "string",
                  "index": "not_analyzed"
               },
               "title": {
                  "type": "string",
                  "analyzer": "full_name",
                  "fields": {
                     "partial": {
                        "type": "string",
                        "index_analyzer": "partial_name",
                        "search_analyzer": "full_name"
                     },
                     "sortable": {
                        "type": "string",
                        "analyzer": "sortable"
                     }
                  }
               },
               "variant_title": {
                  "type": "string",
                  "analyzer": "full_name",
                  "fields": {
                     "partial": {
                        "type": "string",
                        "index_analyzer": "partial_name",
                        "search_analyzer": "full_name"
                     },
                     "sortable": {
                        "type": "string",
                        "analyzer": "sortable"
                     }
                  }
               }
            }
         }
      }
   }
}

Query DSL:

{
  "from":0,
  "size":9,
  "min_score":0.005,
  "query":{
    "filtered":{
      "query":{
        "bool":{
          "should":[
            {
              "match":{
                "title":{
                  "query":"1-MTR",
                  "type":"phrase",
                  "boost":10
                }
              }
            },
            {
              "match":{
                "title":{
                  "query":"1-MTR",
                  "operator":"and",
                  "boost":5,
                  "fuzziness":"0"
                }
              }
            },
            {
              "match":{
                "title":{
                  "query":"1-MTR",
                  "boost":2,
                  "fuzziness":"AUTO"
                }
              }
            },
            {
              "match":{
                "title.partial":{
                  "query":"1-MTR",
                  "boost":5,
                  "fuzziness":"0"
                }
              }
            },
            {
              "multi_match":{
                "query":"1-MTR",
                "type":"cross_fields",
                "fields":[
                  "sku",
                  "sku.partial",
                  "variant_title",
                  "variant_title.partial"
                ],
                "boost":1
              }
            },
            {
              "term": {
                "sku.exact": {
                  "value": "1-MTR",
                  "boost": 200
                }
              }
            }
          ]
        }
      },
      "filter":{
        "bool": {
          "must": [
            {
              "exists":{
                  "field":"sbb"
              }
            }
          ]
        }
      }
    }
  }
}

Expected example source result:

{
     "_source": {
     "sku": "1-MTR",
     "title": "Afghanistan Campaign Tiny Ribbon ",
     "variant_title": "",
     "image": "401_ARACMR.jpg"
}

(Zelfapp) #2

Wish I could delete this post. The issue has been resolved.

My query dsl and mapping are working correctly. The particular SKU I was searching for was missing the "sbb" field, which is a required filter.

Wooops! Maybe something here will be useful to someone else, or moderator, please delete.


(system) #3