Skip to content

Instantly share code, notes, and snippets.

@ianribas
Last active January 8, 2021 13:23
Show Gist options
  • Select an option

  • Save ianribas/f76d20c21bb9f5c0df2f to your computer and use it in GitHub Desktop.

Select an option

Save ianribas/f76d20c21bb9f5c0df2f to your computer and use it in GitHub Desktop.

Revisions

  1. ianribas revised this gist Apr 2, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -46,8 +46,8 @@ curl -XPUT 'http://localhost:9200/multiwordsyns/test/2?pretty' -d '{"text": "wha
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/3?pretty' -d '{"text": "that spider is the size of a man"}'
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/4?pretty&refresh=true' -d '{"text": "spiders eat insects"}'

    # WRONG! should find #1 & #3
    # WRONG! finds only #1, should find #1 & #3
    curl -XPOST 'http://localhost:9200/multiwordsyns/test/_search?pretty' -d '{"query": {"match": {"text": {"query": "spiderman", "operator": "and"}}}}'

    # Also WRONG! should find #1 & #3
    # Also WRONG! finds only #1, should find #1 & #3
    curl -XPOST 'http://localhost:9200/multiwordsyns/test/_search?pretty' -d '{"query": {"match": {"text": {"query": "spider man", "operator": "and"}}}}'
  2. ianribas revised this gist Dec 16, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -46,8 +46,8 @@ curl -XPUT 'http://localhost:9200/multiwordsyns/test/2?pretty' -d '{"text": "wha
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/3?pretty' -d '{"text": "that spider is the size of a man"}'
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/4?pretty&refresh=true' -d '{"text": "spiders eat insects"}'

    # WRONG! should find #1 & #4
    # WRONG! should find #1 & #3
    curl -XPOST 'http://localhost:9200/multiwordsyns/test/_search?pretty' -d '{"query": {"match": {"text": {"query": "spiderman", "operator": "and"}}}}'

    # Also WRONG! should find #1 & #4
    # Also WRONG! should find #1 & #3
    curl -XPOST 'http://localhost:9200/multiwordsyns/test/_search?pretty' -d '{"query": {"match": {"text": {"query": "spider man", "operator": "and"}}}}'
  3. ianribas created this gist Aug 14, 2014.
    53 changes: 53 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/bin/bash

    # delete old index if exists
    curl -XDELETE 'http://localhost:9200/multiwordsyns?pretty'

    # create index with synonym analyzer and mapping
    curl -XPUT 'http://localhost:9200/multiwordsyns?pretty' -d '{
    "settings" : {
    "number_of_replicas": 0,
    "number_of_shards": 1,
    "index": {
    "analysis": {
    "analyzer": {
    "index_time": {
    "tokenizer": "standard",
    "filter": ["standard", "lowercase"]
    },
    "synonym": {
    "tokenizer": "standard",
    "filter": ["standard", "lowercase", "stop", "synonym"]
    }
    },
    "filter": {
    "synonym": {
    "type": "synonym",
    "synonyms": [
    "spider man, spiderman"
    ]
    }
    }
    }
    }
    },
    "mappings": {
    "test": {
    "properties": {
    "text": {"type": "string", "index_analyzer": "index_time", "search_analyzer": "synonym"}
    }
    }
    }
    }'

    # index the test documents
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/1?pretty' -d '{"text": "the adventures of spiderman"}'
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/2?pretty' -d '{"text": "what hath man wrought?"}'
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/3?pretty' -d '{"text": "that spider is the size of a man"}'
    curl -XPUT 'http://localhost:9200/multiwordsyns/test/4?pretty&refresh=true' -d '{"text": "spiders eat insects"}'

    # WRONG! should find #1 & #4
    curl -XPOST 'http://localhost:9200/multiwordsyns/test/_search?pretty' -d '{"query": {"match": {"text": {"query": "spiderman", "operator": "and"}}}}'

    # Also WRONG! should find #1 & #4
    curl -XPOST 'http://localhost:9200/multiwordsyns/test/_search?pretty' -d '{"query": {"match": {"text": {"query": "spider man", "operator": "and"}}}}'