-
Notifications
You must be signed in to change notification settings - Fork 9
/
copy_field_index_name.sh
executable file
·47 lines (47 loc) · 1.37 KB
/
copy_field_index_name.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
#!/bin/bash
#
# This script shows how to implement a copy_field-like functionality in elasticsearch
#
curl -XDELETE localhost:9200/test-idx
echo
curl -XPUT localhost:9200/test-idx -d '{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"doc": {
"properties": {
"first_name": {
"type": "multi_field",
"path": "just_name",
"fields": {
"first_name": {"type": "string", "index": "analyzed"},
"copy": {"type": "string", "index": "analyzed", "index_name": "name"}
}
},
"last_name": {
"type": "multi_field",
"path": "just_name",
"fields": {
"last_name": {"type": "string", "index": "analyzed"},
"copy": {"type": "string", "index": "analyzed", "index_name": "name"}
}
}
}
}
}
}'
echo
curl -XPUT localhost:9200/test-idx/doc/1 -d '{
"first_name": "Shay",
"last_name": "Banon"
}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Shay"
echo
curl "localhost:9200/test-idx/doc/_search?q=name:Banon"