Skip to content

Instantly share code, notes, and snippets.

@tylerfontaine
Last active November 16, 2016 22:03
Show Gist options
  • Save tylerfontaine/b34a36d17e8faf0f9fe5af3ad7d6f880 to your computer and use it in GitHub Desktop.
Save tylerfontaine/b34a36d17e8faf0f9fe5af3ad7d6f880 to your computer and use it in GitHub Desktop.
multi-field boosting bug Repro

Step 1 - create the mapping

PUT subfield-repro
{
   "settings": {
      "analysis": {
         "analyzer": {
            "reverser": {
               "type": "custom",
               "tokenizer": "keyword",
               "filter": [
                  "lowercase",
                  "reverse"
               ]
            },
            "whole": {
               "type": "custom",
               "tokenizer": "keyword",
               "filter": [
                  "lowercase"
               ]
            }
         }
      }
   },
   "mappings": {
      "type": {
         "properties": {
            "textfield": {
               "type": "text", 
               "analyzer": "standard",
               "boost": 3, 
               "fields":  {
                     "whole": {
                         "boost": 2,
                        "analyzer": "whole",
                        "type": "text"
                     },
                     "reverse": {
                         
                        "analyzer": "reverser",
                        "type": "text"
                     }
                  }
            }
         }
      }
   }
}

Step 2 - put a document to test against

POST subfield-repro/type
{
    "textfield" : "http://google.com/boots"
}

Step 3 - Search against the 3 fields:

This one returns the document

GET subfield-repro/type/_search
{
    "query" : {
        "match_phrase_prefix": {
           "textfield": "http"
        }
        }
}

this one returns no results

GET subfield-repro/type/_search
{
    "query" : {
        "match_phrase_prefix": {
           "textfield.whole": "http"
        }
        }
}

This one returns the document

GET subfield-repro/type/_search
{
    "explain": true, 
    "query" : {
        "match_phrase_prefix": {
           "textfield.reverse": "boots"
        }
        }
}

However if you don't boost (or only boost with a value of 1), all 3 return results as expected.

Mapping for all 3 of the above quries to return the document:

PUT subfield-repro
{
   "settings": {
      "analysis": {
         "analyzer": {
            "reverser": {
               "type": "custom",
               "tokenizer": "keyword",
               "filter": [
                  "lowercase",
                  "reverse"
               ]
            },
            "whole": {
               "type": "custom",
               "tokenizer": "keyword",
               "filter": [
                  "lowercase"
               ]
            }
         }
      }
   },
   "mappings": {
      "type": {
         "properties": {
            "textfield": {
               "type": "text", 
               "analyzer": "standard",
               "boost": 3, 
               "fields":  {
                     "whole": {
                        "analyzer": "whole",
                        "type": "text"
                     },
                     "reverse": {
                         
                        "analyzer": "reverser",
                        "type": "text"
                     }
                  }
            }
         }
      }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment