Skip to content

Instantly share code, notes, and snippets.

@darklow
Last active December 21, 2015 14:09

Revisions

  1. darklow revised this gist Aug 23, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion es_completion_suggest.sh
    Original file line number Diff line number Diff line change
    @@ -68,5 +68,7 @@ curl -X POST "http://localhost:9200/hotels/_suggest?pretty=true" -d '

    echo

    # Found using first letters of first words - M, C or G
    # Can't find using Mu, Mun, Munich, City, General, so on
    # anyone know why?
    Thank you
    # Thank you
  2. darklow created this gist Aug 23, 2013.
    72 changes: 72 additions & 0 deletions es_completion_suggest.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    #!/bin/bash
    # ========================================
    # Testing completion suggest in ElasticSearch
    # ========================================

    curl -X DELETE localhost:9200/hotels
    curl -X PUT localhost:9200/hotels -d '
    {
    "mappings": {
    "hotel" : {
    "properties" : {
    "name" : { "type" : "string" },
    "city" : { "type" : "string" },
    "name_suggest" : {
    "type" : "completion",
    "payloads" : true
    }
    }
    }
    }
    }'

    curl -X PUT localhost:9200/hotels/hotel/3 -d '
    {
    "name" : "Courtyard by Marriot Munich City",
    "city" : "Munich",
    "name_suggest" : {
    "input" : [
    "Courtyard by Marriot Munich City",
    "Marriot Munich City",
    "General Munich Hotel"
    ],
    "output": "Hotel Marriot",
    "weight": 15,
    "payload": { "hotel_id": 3}
    }
    }'

    curl -X POST "http://localhost:9200/hotels/_refresh"

    # Some debug info
    echo
    echo "name_suggest input: { \"Courtyard by Marriot Munich City\", \"Marriot Munich City\", \"General Munich Hotel\" }"

    echo
    echo "# Found using first letters of first words - M, C or G"
    curl -X POST "http://localhost:9200/hotels/_suggest?pretty=true" -d '
    {
    "hotels": {
    "text": "M",
    "completion": {
    "field": "name_suggest"
    }
    }
    }'

    echo
    echo "# Can't find using Mu, Mun, Munich, City, General, so on"
    curl -X POST "http://localhost:9200/hotels/_suggest?pretty=true" -d '
    {
    "hotels": {
    "text": "Munich",
    "completion": {
    "field": "name_suggest"
    }
    }
    }'

    echo

    # anyone know why?
    Thank you