Skip to content

Instantly share code, notes, and snippets.

@phil-lavin
Created December 4, 2013 09:24
Show Gist options
  • Save phil-lavin/7784696 to your computer and use it in GitHub Desktop.
Save phil-lavin/7784696 to your computer and use it in GitHub Desktop.

Search is as follows:

{"query":{"query_string":{"query":"armschel"}}}

My index has been defined as follows:

[
    'number_of_shards' => 4,
    'number_of_replicas' => 1,
    'analysis' => [
        'analyzer' => [
            'index_analyzer' => [
                'type' => 'custom',
                'tokenizer' => 'standard',
                'filter' => ['lowercase', 'snowball', 'metaphone_phonetic']
            ],
            'search_analyzer' => [
                'type' => 'custom',
                'tokenizer' => 'standard',
                'filter' => ['lowercase', 'snowball', 'metaphone_phonetic']
            ],
            'description_analyzer' => [
                'type' => 'custom',
                'tokenizer' => 'standard',
                'filter' => ['metaphone_phonetic', 'snowball'],
            ],
            'domain_name_analyzer' => [
                'type' => 'custom',
                'tokenizer' => 'domain_ngram_tokenizer',
                'filter' => ['lowercase']
            ],
        ],
        'filter' => [
            'metaphone_phonetic' => [
                'type' => 'phonetic',
                'encoder' => 'metaphone',
                'replace' => false,
            ],
        ],
        'tokenizer' => [
            'domain_ngram_tokenizer' => [
                'type' => 'nGram',
                'min_gram' => '4',
                'max_gram' => '45'
            ],
        ],
    ],
],

My mapping is as follows:

{
  "sites" : {
    "index_analyzer" : "index_analyzer",
    "search_analyzer" : "search_analyzer",
    "properties" : {
      "client_comments" : {
        "type" : "string"
      },
      "client_id" : {
        "type" : "integer",
        "index" : "no"
      },
      "client_name" : {
        "type" : "string",
        "boost" : 3.0
      },
      "cluster_name" : {
        "type" : "string",
        "index" : "no"
      },
      "comments" : {
        "type" : "string"
      },
      "domains" : {
        "type" : "string",
        "index_analyzer" : "domain_name_analyzer"
      },
      "external_ip" : {
        "type" : "ip",
        "index" : "analyzed"
      },
      "id" : {
        "type" : "integer",
        "index" : "no"
      },
      "primary_domain" : {
        "type" : "string",
        "index" : "no"
      },
      "test_site" : {
        "type" : "boolean",
        "index" : "no"
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment