用于搜索的弹性搜索索引

时间:2018-05-22 18:47:46

标签: elasticsearch

使用以下索引,在metricname_text上,假设我们有一个包含字符串1048avg_percent_memory_used的文档。我发现如果我为搜索结果键入1048,我会找到它。但是,如果我输入percent_memory,则无法找到任何结果。有人能指出我在正确的方向上正确的方向用来部分匹配一个单词,但不一定从单词的开头锚定?我也不确定我match查询是否是正确的搜索类型。

{
  "settings": {
    "analysis": {

      "filter": {
          "autocomplete_filter": { 
              "type":     "edge_ngram",
              "min_gram": 1,
              "max_gram": 20
          }
      },

      "analyzer": {
          "autocomplete": {
              "type":      "custom",
              "tokenizer": "standard",
              "filter": [
                  "lowercase",
                  "autocomplete_filter" 
              ]
          }
      }
    }
  },
  "mappings": {
    "metric": {
      "properties": {
        "metricname_text": {
          "type": "text",
          "analyzer": "autocomplete"
        },
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

metadata = {
  "settings": {
      "analysis": {
          "filter": {
              "trigrams_filter": {
                  "type":     "ngram",
                  "min_gram": 3,
                  "max_gram": 3
              }
          },
          "analyzer": {
              "trigrams": {
                  "type":      "custom",
                  "tokenizer": "standard",
                  "filter":   [
                      "lowercase",
                      "trigrams_filter"
                  ]
              }
          }
      }
  },
  "mappings": {
    "metric": {
      "properties": {
        "metricname_text": {
            "type":     "text",
            "analyzer": "trigrams"
        },
      }
    }
  }
}