-
Notifications
You must be signed in to change notification settings - Fork 9
/
indices_filter.sh
executable file
·68 lines (64 loc) · 1.92 KB
/
indices_filter.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
60
61
62
63
64
65
66
67
68
#!/bin/bash
#
# This script shows how to use indices filter to search several indices with different filters in the same request
#
# Recreate both indices
curl -s -XDELETE "localhost:9200/foo-idx,bar-idx?pretty"
curl -s -XPUT "localhost:9200/foo-idx?pretty" -d '{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}'
curl -s -XPUT "localhost:9200/bar-idx?pretty" -d '{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}'
# Index some test data
curl -s -XPUT "localhost:9200/bar-idx/doc/1?pretty" -d '{
"name": "foo"
}'
curl -s -XPUT "localhost:9200/bar-idx/doc/2?pretty" -d '{
"name": "bar"
}'
curl -s -XPUT "localhost:9200/foo-idx/doc/1?pretty" -d '{
"name": "foo"
}'
curl -s -XPUT "localhost:9200/foo-idx/doc/2?pretty" -d '{
"name": "bar"
}'
curl -s -XPOST "localhost:9200/_refresh"
# Search for "foo" in the "foo-idx" and "bar" in the "bar-idx"
curl -s -XPOST "localhost:9200/foo-idx,bar-idx/_search?pretty" -d '{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [{
"indices": {
"indices": ["foo-idx"],
"filter": {
"term": {
"name": "foo"
}
},
"no_match_filter" : "none"
}
}, {
"indices": {
"indices": ["bar-idx"],
"filter": {
"term": {
"name": "bar"
}
},
"no_match_filter" : "none"
}
}]
}
}
}
}
}'