Skip to content

Instantly share code, notes, and snippets.

@alexbrasetvik
Created November 14, 2013 10:29

Revisions

  1. alexbrasetvik revised this gist Nov 14, 2013. No changes.
  2. alexbrasetvik revised this gist Nov 14, 2013. 3 changed files with 9 additions and 1 deletion.
    5 changes: 5 additions & 0 deletions analysis.yaml
    Original file line number Diff line number Diff line change
    @@ -4,3 +4,8 @@ analyzer:
    standard_tokenize_only:
    type: custom
    tokenizer: standard

    # Switch to the "Analysis"-tab to see how the text gets tokenized by default.
    standard:
    type: standard

    3 changes: 3 additions & 0 deletions play.sh
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,9 @@ curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
    "standard_tokenize_only": {
    "type": "custom",
    "tokenizer": "standard"
    },
    "standard": {
    "type": "standard"
    }
    }
    }
    2 changes: 1 addition & 1 deletion play.yaml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Auto generated by Found's Play-tool at 2013-11-14T11:29:41+01:00
    # Auto generated by Found's Play-tool at 2013-11-14T11:31:15+01:00
    version: 0
    title: Simple case sensitive search
    description: "Standard tokenization, but without the lowercasing and stopword removal."
  3. alexbrasetvik created this gist Nov 14, 2013.
    6 changes: 6 additions & 0 deletions analysis.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    text: This text will be used if nothing else is specified.

    analyzer:
    standard_tokenize_only:
    type: custom
    tokenizer: standard
    5 changes: 5 additions & 0 deletions documents.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    title: Foo Bar

    ---

    title: foo bar
    6 changes: 6 additions & 0 deletions mappings.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    type:
    properties:
    title:
    type: string
    analyzer: standard_tokenize_only

    65 changes: 65 additions & 0 deletions play.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    #!/bin/bash

    export ELASTICSEARCH_ENDPOINT="http://localhost:9200"

    # Create indexes

    curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
    "settings": {
    "analysis": {
    "text": "This text will be used if nothing else is specified.",
    "analyzer": {
    "standard_tokenize_only": {
    "type": "custom",
    "tokenizer": "standard"
    }
    }
    }
    },
    "mappings": {
    "type": {
    "properties": {
    "title": {
    "type": "string",
    "analyzer": "standard_tokenize_only"
    }
    }
    }
    }
    }'


    # Index documents
    curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
    {"index":{"_index":"play","_type":"type"}}
    {"title":"Foo Bar"}
    {"index":{"_index":"play","_type":"type"}}
    {"title":"foo bar"}
    '

    # Do searches

    curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
    {
    "query": {
    "match": {
    "title": {
    "query": "Foo"
    }
    }
    }
    }
    '

    curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
    {
    "query": {
    "match": {
    "title": {
    "query": "foo"
    }
    }
    }
    }
    '

    4 changes: 4 additions & 0 deletions play.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # Auto generated by Found's Play-tool at 2013-11-14T11:29:41+01:00
    version: 0
    title: Simple case sensitive search
    description: "Standard tokenization, but without the lowercasing and stopword removal."
    13 changes: 13 additions & 0 deletions searches.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    query:
    match:
    title:
    # This will only match the first document.
    query: Foo

    ---

    query:
    match:
    title:
    # This will match the second document only
    query: foo