3

我们有一个包含 mac 地址字段的类型。数据是使用jdbc River带来的

原因是当我们在 mac_address 字段上运行术语聚合时,结果看起来该字段被分解为索引键:

行动:

GET index/type/_search?search_type=count
{
    "aggs" : { 
        "uniqe_macs" : { 
            "terms" : {
              "field" : "mac_address" 
            }
        }
    }
}

结果:

  "aggregations": {
     "uniqe_visitors": {
        "buckets": [
           {
              "key": "00",
              "doc_count": 1608759
           },
           {
              "key": "10",
              "doc_count": 674633
           },
           {
              "key": "18",
              "doc_count": 588591
           },
           {
              "key": "f0",
              "doc_count": 544897
           },
           {
              "key": "60",
              "doc_count": 538841
           },
           {
              "key": "40",
              "doc_count": 529085
           },
           {
              "key": "08",
              "doc_count": 523681
           },
           {
              "key": "d0",
              "doc_count": 515774
           },
           {
              "key": "54",
              "doc_count": 514771
           },
           {
              "key": "04",
              "doc_count": 509629
           }
        ]
     }
    }

可以做些什么来强制弹性映射该字段而不是将其分解为键?

4

2 回答 2

4

您可以尝试在 es 字段上使用以下映射自定义分析器吗mac_address

定义分析器

curl -XPUT http://localhost:9200/INDEX  -d '
{
    "settings" : {
        "analysis" : {
            "analyzer" : {
                "my_edge_ngram_analyzer" : {
                    "tokenizer" : "my_edge_ngram_tokenizer"
                }
            },
            "tokenizer" : {
                "my_edge_ngram_tokenizer" : {
                    "type" : "edgeNGram",
                    "min_gram" : "2",
                    "max_gram" : "17"
                }
            }
        }
    }
}'

应用映射

curl -XPUT http://localhost:9200/INDEX/TYPE/_mapping  -d '
{
    "TYPE": {
        "properties" {
            "mac_address": {
                "type": "string",
                "index_analyzer" : "my_edge_ngram_analyzer",
                "search_analyzer": "keyword"
            }
        }
    }
}'
于 2014-09-09T13:07:18.337 回答
0

对我来说,更容易为 定义一个原始多字段mac_adress并将其设置为,如此not_analyzed所述。虽然它不适用于旧数据,但无需使用新分析器更改索引。

curl -XPUT http://localhost:9200/INDEX/TYPE/_mapping -d'

{
    "TYPE" : {
        "properties" : {
            "mac_address" : {
                "type" : "string",
                "fields":{
                    "raw" : {
                      "type": "string",
                      "index": "not_analyzed"
                    }
                  }
            }
        }
    }
}'

然后对于聚合,您只需要使用该字段mac_address.raw

curl -XPOST http://localhost:9200/INDEX/TYPE/_search?search_type=count -d'

{
    "aggs" : { 
        "unique_macs" : { 
            "terms" : {
              "field" : "mac_address.raw" 
            }
        }
    }
}'
于 2015-01-03T11:50:18.877 回答