3

We have a type that contains mac address field. the data is brought using jdbc river

The cause is that when we run a term aggregation on the mac_address field the results looks like the field is broke into indexed keys:

Action:

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

Result:

  "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
           }
        ]
     }
    }

What can be done to force elastic to map this field and not to break it into keys?

Ben Diamant
  • 6,186
  • 4
  • 35
  • 50

2 Answers2

4

Can you try with following mapping, custom analyzer on es field mac_address.

Define analyzer

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"
                }
            }
        }
    }
}'

Apply mapping

curl -XPUT http://localhost:9200/INDEX/TYPE/_mapping  -d '
{
    "TYPE": {
        "properties" {
            "mac_address": {
                "type": "string",
                "index_analyzer" : "my_edge_ngram_analyzer",
                "search_analyzer": "keyword"
            }
        }
    }
}'
prayagupa
  • 30,204
  • 14
  • 155
  • 192
0

For me it was easier to define a raw multifield for the mac_adress and set it to not_analyzed, as described here. Although it did not work for the old data, no need to alter the index with a new analyzer.

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

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

Then for the aggregation you just need to use the field mac_address.raw:

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

{
    "aggs" : { 
        "unique_macs" : { 
            "terms" : {
              "field" : "mac_address.raw" 
            }
        }
    }
}'
kahlo
  • 2,314
  • 3
  • 28
  • 37