Search code examples
elasticsearchchewy-gem

Elastic search 8.7 default field search not working as expected


I am facing an issue with default field search for elastic search version 8.7

Consider elastic search with index name customers with below data fields

{
    "customer_name":"ABC Manufacturers",
    "vendor_name":"XZY Manufacturers",
    "status":"Active",
    "address":""
}

Mapping :

{
  "mappings": {
    "properties": {
      "customer_name": {
        "type": "text",
        "analyzer": "string_analyzer"
      },
      "status": {
        "type": "text",
        "analyzer": "string_analyzer"
      },
      "vendor_name": {
        "type": "text",
        "analyzer": "string_analyzer"
      },
      ...
    }
  }
}

Settings:

{
  "settings": {
    "index": {
      "max_ngram_diff": "15",
      "routing": {
        "allocation": {
          "include": {
            "_tier_preference": "data_content"
          }
        }
      },
      "number_of_shards": "1",
      "analysis": {
        "filter": {
          "ngram_filter": {
            "type": "edge_ngram",
            "min_gram": "2",
            "max_gram": "15"
          }
        },
        "analyzer": {
          "string_analyzer": {
            "filter": [
              "lowercase",
              "ngram_filter"
            ],
            "fuzziness": "AUTO",
            "type": "custom",
            "tokenizer": "standard"
          },
          "ngram_analyzer": {
            "filter": [
              "lowercase",
              "ngram_filter"
            ],
            "type": "custom",
            "tokenizer": "ngram_tokenizer"
          }
        },
        "tokenizer": {
          "ngram_tokenizer": {
            "type": "ngram",
            "min_gram": "3",
            "max_gram": "15"
          }
        }
      }
    }
  },
  "defaults": {
    "index": {
      "lifecycle": {
        "name": "",
        "parse_origination_date": "false",
        "step": {
          "wait_time_threshold": "12h"
        },
        "indexing_complete": "false",
        "rollover_alias": "",
        "origination_date": "-1"
      },
      "mode": "standard",
      "routing_partition_size": "1",
      "mapping": {
        "coerce": "false",
        "nested_fields": {
          "limit": "50"
        },
        "depth": {
          "limit": "20"
        },
        "field_name_length": {
          "limit": "9223372036854775807"
        },
        "total_fields": {
          "limit": "1000"
        },
        "nested_objects": {
          "limit": "10000"
        },
        "ignore_malformed": "false",
        "dimension_fields": {
          "limit": "16"
        }
      },
      "max_script_fields": "32",
      "query": {
        "default_field": [
          "*"
        ],
        "parse": {
          "allow_unmapped_fields": "true"
        }
      },
      "auto_expand_replicas": "false",
      "recovery": {
        "type": ""
      },
      "fielddata": {
        "cache": "node"
      },
      "queries": {
        "cache": {
          "enabled": "true"
        }
      },
      "query_string": {
        "lenient": "false"
      }
    }
  }
}

Earlier I was on version 8.2 where below query was working fine as it was searching through all default fields, which was by default *. But after upgradation to 8.7, I am not able to get result using same query.

It seems that this query is fetching result only from vendor_name, may be it is considering vendor_name as default but in setting I can still see default field as *. Is there any deprecation or behavioural changes made with 8.7 upgradation. Need help if any one has faces similar issue.

Also, I get expected data for 8.7 if I pass fields(fields:["customer_name"]) to below query but if I pass fields as ["customer_name","vendor_name"], I am not getting any matches from customer_name.

GET customers/_search
{
  "query": {
    "query_string": {
      "query": "ABC",
      "default_operator": "AND"
    }
  }
}

Solution

  • After debugging and following up with the Elastic team, we got to know this is a known issue/bug in Elastic version 8.7.

    Upgrading to 8.8.x helps us to get this fix.