当这些字符串中是数字时,Elasticsearch不起作用

abithluo  于 2023-10-17  发布在  ElasticSearch
关注(0)|答案(1)|浏览(108)

我有一个这样的ES文档:

{
  "_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"
    ],
  }
}

如果我使用这样的查询,它什么也不返回。

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

如果我删除“uc4”,它可能会命中此文档。

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

我应该怎么做才能使用'uc4.abc.done',它会击中文档?
touchTriggers字段的Map

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

下面是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"
        }
      }
    }
  }
}

是否需要更改此索引的设置或Map?

zujrkrfu

zujrkrfu1#

您需要在touchTriggers.keyword字段上运行wildcard查询,您将获得预期的响应。

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

相关问题