querqy / querqy-elasticsearch

Querqy for Elasticsearch
Apache License 2.0
44 stars 17 forks source link

Rewriter Filter with dot in name #17

Open Leo-VK opened 3 years ago

Leo-VK commented 3 years ago

Hi everyone

While using the parameters to filter the selected rewriters, we encountered an issue. An example index with settings is given below. It seems that a dot in the name of the rewriter leads to unexpected behaviour. If we upload two identical rewriters, one with a dot (_commonrules.test) and another with a underscore (_common_rulestest) as difference in the name, the filter does not have the same effect. In the case of the underscore, the filter is applied as expected. However, in the case of the dot, the filter is appearently ignored. Other functionalities besides the filter seem to work for both cases. The example was done with querqy version 1.4.es721.0.

Best regards

PUT /test
{
  "mappings": {
    "properties": {
      "title": { "type": "text" },
      "brand": { "type": "text" },
      "shortSummary": { "type": "text" }
    }
  }
}

PUT /test/_doc/1
{
  "title": "Notebook",
  "brand": "HP",
  "shortSummary": "very slim"
}
PUT /test/_doc/2
{
  "title": "Laptop",
  "brand": "Apple",
  "shortSummary": "very slim"
}

POST test/_search
{
  "query": {
    "match": {
      "title": "Notebook"
    }
  }
}

PUT  /_querqy/rewriter/common_rules_test
{
    "class": "querqy.elasticsearch.rewriter.SimpleCommonRulesRewriterFactory",
    "config": {
        "rules" : "notebook => \nSYNONYM: laptop \n UP(1000): laptop \n @{ \n _id: \"ID1\" \n, priority: 5, \n group: [\"hardware\"], \n tenant: [\"t1\", \"t3\"] \n }@"
    }
}

PUT  /_querqy/rewriter/common_rules.test
{
    "class": "querqy.elasticsearch.rewriter.SimpleCommonRulesRewriterFactory",
    "config": {
        "rules" : "notebook => \nSYNONYM: laptop \n UP(1000): laptop \n @{ \n _id: \"ID1\" \n, priority: 5, \n group: [\"hardware\"], \n tenant: [\"t1\", \"t3\"] \n }@"
    }
}

#Filter is not applied correctly, synonym is applied, notebook and laptop are returned
POST test/_search
{
   "query": {
       "querqy": {
           "matching_query": {
               "query": "notebook"
           },
           "query_fields": [
               "title^3.0", "brand^2.1", "shortSummary"
           ],
           "rewriters": [
             {
               "name": "common_rules.test",
               "params": {
                 "criteria": {
                   "filter": "$[?(\"ThisIsJustATest\" in @.group)]"
                 }
               }
             }]
      }
  }
}

#Filter is applied correctly, synonym is not applied, only notebook is returned
POST test/_search
{
   "query": {
       "querqy": {
           "matching_query": {
               "query": "notebook" 
           },
           "query_fields": [
               "title^3.0", "brand^2.1", "shortSummary"
           ],
           "rewriters": [
             {
               "name": "common_rules_test",
               "params": {
                 "criteria": {
                   "filter": "$[?(\"ThisIsJustATest\" in @.group)]"
                 }
               }
             }]
      }
  }
}
renekrie commented 3 years ago

Thank you for reporting this @Leo-VK!

This error looks a bit weird. It might be related to how rewriter-specific parameter names are handled in Querqy Core - we'll figure it out!

(Note that there is an update to the Querqy ES version that you are using, which fixes #15)