-
Notifications
You must be signed in to change notification settings - Fork 9
/
number_of_matches.sh
executable file
·59 lines (59 loc) · 1.8 KB
/
number_of_matches.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# This script demonstrates how to calculate number of matched term in the query
#
curl -XDELETE localhost:9200/test-idx
curl -XPUT localhost:9200/test-idx -d '{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"name": {"type": "string"}
}
}
}
}'
curl -XPUT "localhost:9200/test-idx/doc/1" -d '{"name": "foo bar baz"}'
curl -XPUT "localhost:9200/test-idx/doc/2" -d '{"name": "foo abc xyz"}'
curl -XPUT "localhost:9200/test-idx/doc/3" -d '{"name": "bar baz"}'
curl -XPUT "localhost:9200/test-idx/doc/4" -d '{"name": "abc xyz"}'
curl -XPOST localhost:9200/_refresh
echo
curl "localhost:9200/test-idx/doc/_search?pretty=true" -d '{
"explain": false,
"query": {
"custom_filters_score": {
"query": {
"constant_score" : {
"query": {
"bool": {
"should": [{
"match": {"name": "foo"}
},{
"match": {"name": "bar"}
},{
"match": {"name": "baz"}
}]
}
}
}
},
"filters": [{
"filter" : { "query" : { "match": {"name": "foo"} } },
"boost" : "1"
},
{
"filter" : { "query" : { "match": {"name": "bar"} } },
"boost" : "1"
},
{
"filter" : { "query" : { "match": {"name": "baz"} } },
"boost" : "1"
}],
"score_mode": "total"
}
}
}'