Skip to content

Instantly share code, notes, and snippets.

@kimchy
Created March 8, 2012 21:45

Revisions

  1. kimchy revised this gist Mar 8, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
    }'

    # Now, combine the two, should clauses are sums of scores, so have the negative boost query boost by a negative factor
    curl 'localhost:9200/test/_search?pretty=1&explain=1' -d '{
    curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
    "query" : {
    "bool" : {
    "should" : [
  2. kimchy created this gist Mar 8, 2012.
    65 changes: 65 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    curl -XPUT localhost:9200/test -d '{
    "settings" : {
    "index.number_of_shards" : 1,
    "index.number_of_replicas" : 0
    }
    }'

    curl -XPUT localhost:9200/test/type/1 -d '{
    "name" : "Awesometastic 1000",
    "type" : "TV Remote"
    }'


    curl -XPUT localhost:9200/test/type/2 -d '{
    "name" : "Awesometastic 1000 TV Remote",
    "type" : "TV Remote"
    }'

    curl -XPOST localhost:9200/test/_refresh

    # One without negative boosting
    curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
    "query" : {
    "bool" : {
    "should" : [
    { "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 10}} },
    { "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 5}} },
    ]
    }
    }
    }'

    # The query that gives us ones that try and cheat the system (higher score means that they are trying to cheat more...)
    curl 'localhost:9200/test/_search?pretty=1&explain=0' -d '{
    "query" : {
    "bool" : {
    "must" : [
    { "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} },
    { "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} }
    ],
    "boost" : 1
    }
    }
    }'

    # Now, combine the two, should clauses are sums of scores, so have the negative boost query boost by a negative factor
    curl 'localhost:9200/test/_search?pretty=1&explain=1' -d '{
    "query" : {
    "bool" : {
    "should" : [
    { "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 10}} },
    { "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 5}} },
    {
    "bool" : {
    "must" : [
    { "text" : {"name" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} },
    { "text" : {"type" : {"query" : "The Awesometastic TV Remote", "boost" : 1}} }
    ],
    "boost" : -20
    }
    }
    ]
    }
    }
    }'