Search code examples
elasticsearchsearchwildcard

Elasticsearch wildcard does not work when these is a number in the string


I have an es document like this:

{
  "_index" : "jobpipeline",
  "_type" : "_doc",
  "_id" : "xxxx",
  "_version" : 19,
  "_seq_no" : 417185,
  "_primary_term" : 18,
  "found" : true,
  "_source" : {
    "_boostScoreFactor" : 1.0,
    "type" : "jobpipeline",
    "owner" : [
      ""
    ],
    "title" : "xxxx",
    "watchTriggers" : [
      "uc4.abc",
      "uc4.abc.done"
    ],
    "touchTriggers" : [
      "uc4.abc.done"
    ],
  }
}

If I use a query like this, it returns nothing.

GET jobpipeline/_search
{
  "query": {
    "wildcard": {
      "touchTriggers": "*uc4.abc.done*"
    }
  }
}

It can hit this document if I remove the 'uc4.'.

GET dd-jobpipeline/_search
{
  "query": {
    "wildcard": {
      "touchTriggers": "*abc.done*"
    }
  }
}

What should I do to use 'uc4.abc.done' and it will hit the document?

Mapping of touchTriggers field

        "touchTriggers" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }

Here is the setting of JobPipeline Index.

{
  "jobpipeline" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "total_shards_per_node" : "2"
          }
        },
        "number_of_shards" : "1",
        "provided_name" : "jobpipeline",
        "creation_date" : "1675246845838",
        "unassigned" : {
          "node_left" : {
            "delayed_timeout" : "15m"
          }
        },
        "analysis" : {
          "filter" : {
            "discovery_stemmer" : {
              "type" : "stemmer",
              "language" : "porter2"
            },
            "discovery_stemmer_possessive" : {
              "type" : "stemmer",
              "language" : "minimal_english"
            },
            "discovery_synonym_abbr" : {
              "type" : "synonym_graph",
              "synonyms" : [
                "BN => browse node"
              ]
            }
          },
          "char_filter" : {
            "discovery_charfilter" : {
              "type" : "mapping",
              "mappings" : [
                ".=>|",
                "_=>|",
                "# => number",
                "% => percentage",
                "& => and",
                "+ => browse node"
              ]
            }
          },
          "normalizer" : {
            "lowercase" : {
              "filter" : [
                "lowercase"
              ],
              "type" : "custom",
              "char_filter" : [ ]
            }
          },
          "analyzer" : {
            "discovery_index_analyzer" : {
              "filter" : [
                "lowercase",
                "discovery_synonym_abbr"
              ],
              "char_filter" : [
                "discovery_charfilter"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            }
          }
        },
        "number_of_replicas" : "2",
        "uuid" : "FtylpFoeRFSG6QVBVdoYOg",
        "version" : {
          "created" : "135238227"
        }
      }
    }
  }
}

Do I need to change the setting or mapping of this index?


Solution

  • You need to run the wildcard query on the touchTriggers.keyword field and you will get the expected response.

    GET jobpipeline/_search
    {
      "query": {
        "wildcard": {
          "touchTriggers.keyword": "*uc4.abc.done*"
        }                 ^^^^^
      }
    }