Last active
August 29, 2015 14:03
-
-
Save hmrizin/da8414d844a8a39fc832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# cleanup | |
# | |
curl -XDELETE "http://localhost:9200/user" | |
# | |
# add documents | |
# | |
curl -XPOST "http://localhost:9200/user/profile/" -d '{"id": "p001", "fname": "foo", "lname": "bar"}' | |
curl -XPOST "http://localhost:9200/user/profile/" -d '{"id": "p002", "fname": "foo", "lname": "baz"}' | |
# | |
# test | |
# | |
curl -XPOST "localhost:9200/user/profile/_search?pretty=true" -d ' | |
{ | |
"query" : { | |
"bool" : { | |
"should" : [{ | |
"match" : { | |
"id" : { | |
"query" : "p001", | |
"type" : "boolean", | |
"_name" : "id_match" | |
} | |
} | |
}, { | |
"function_score" : { | |
"query" : { | |
"match" : { | |
"id" : { | |
"query" : "garbagedonotmatch", | |
"type" : "boolean", | |
"_name" : "id_donot_match" | |
} | |
} | |
}, | |
"functions" : [{ | |
"filter" : { | |
"query" : { | |
"bool" : { | |
"should" : [{ | |
"match_all" : {} | |
} | |
], | |
"_name" : "inner_match_all" | |
} | |
} | |
}, | |
"script_score" : { | |
"script" : "_score * 1000" | |
} | |
} | |
], | |
"score_mode" : "multiply", | |
"boost_mode" : "mult" | |
} | |
} | |
] | |
} | |
} | |
}' | |
# | |
# result | |
# | |
{ | |
"took" : 5, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.04500804, | |
"hits" : [ { | |
"_index" : "user", | |
"_type" : "profile", | |
"_id" : "QicWMF1sQgKhKSsv7DTqXQ", | |
"_score" : 0.04500804, "_source" : {"id": "p001", "fname": "foo", "lname": "bar"}, | |
"matched_filters" : [ "inner_match_all", "id_match" ] | |
} ] | |
} | |
} | |
# | |
# result with explaination | |
# | |
{ | |
"took" : 4, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 0.04500804, | |
"hits" : [ { | |
"_shard" : 4, | |
"_node" : "DdI7GQ8uQbCanscCspshWg", | |
"_index" : "user", | |
"_type" : "profile", | |
"_id" : "QicWMF1sQgKhKSsv7DTqXQ", | |
"_score" : 0.04500804, "_source" : {"id": "p001", "fname": "foo", "lname": "bar"}, | |
"matched_filters" : [ "inner_match_all", "id_match" ], | |
"_explanation" : { | |
"value" : 0.04500804, | |
"description" : "product of:", | |
"details" : [ { | |
"value" : 0.09001608, | |
"description" : "sum of:", | |
"details" : [ { | |
"value" : 0.09001608, | |
"description" : "weight(id:p001 in 0) [PerFieldSimilarity], result of:", | |
"details" : [ { | |
"value" : 0.09001608, | |
"description" : "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:", | |
"details" : [ { | |
"value" : 0.29335263, | |
"description" : "queryWeight, product of:", | |
"details" : [ { | |
"value" : 0.30685282, | |
"description" : "idf(docFreq=1, maxDocs=1)" | |
}, { | |
"value" : 0.9560043, | |
"description" : "queryNorm" | |
} ] | |
}, { | |
"value" : 0.30685282, | |
"description" : "fieldWeight in 0, product of:", | |
"details" : [ { | |
"value" : 1.0, | |
"description" : "tf(freq=1.0), with freq of:", | |
"details" : [ { | |
"value" : 1.0, | |
"description" : "termFreq=1.0" | |
} ] | |
}, { | |
"value" : 0.30685282, | |
"description" : "idf(docFreq=1, maxDocs=1)" | |
}, { | |
"value" : 1.0, | |
"description" : "fieldNorm(doc=0)" | |
} ] | |
} ] | |
} ] | |
} ] | |
}, { | |
"value" : 0.5, | |
"description" : "coord(1/2)" | |
} ] | |
} | |
} ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment