-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplore-es.ps1
43 lines (36 loc) · 1.2 KB
/
explore-es.ps1
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
$EsHost = "localhost:9200"
$EsAddress = "http://$EsHost"
# info
Invoke-WebRequest -Method GET $EsAddress
# create index
Invoke-WebRequest -Method PUT "$EsAddress/trec"
Invoke-WebRequest -Method PUT "$EsAddress/trec" -ContentType 'application/json' -Body (@{
"settings" = @{
"number_of_shards" = 1
"similarity" = @{
"default" = @{
"type" = "BM25"
"b" = 0
"k1" = 0.9
}
}
}
} | ConvertTo-Json -Depth 25)
# add documents
Invoke-WebRequest -Method POST "$EsAddress/trec/_doc" -ContentType 'application/json' -Body (@{
'title' = 'Covid-19 study'
'content' = 'some flu text'
} | ConvertTo-Json -Depth 25)
# get all
Invoke-WebRequest -Method POST "$EsAddress/trec/_search" -ContentType 'application/json' -Body (@{
'query' = @{ "match_all" = @{} }
} | ConvertTo-Json -Depth 25)
# get query
(Invoke-WebRequest -Method POST "$EsAddress/trec/_search" -ContentType 'application/json' -Body (@{
'query' = @{
"multi_match" = @{
"query" = "What is flu?"
"fields" = @("title", "content")
}
}
} | ConvertTo-Json -Depth 25)).Content | python -m json.tool