66 lines
1.3 KiB
Plaintext
66 lines
1.3 KiB
Plaintext
// This file is autogenerated, DO NOT EDIT
|
|
// Use `node scripts/generate-docs-examples.js` to generate the docs examples
|
|
|
|
[source, js]
|
|
----
|
|
const response = await client.indices.create({
|
|
index: "index",
|
|
settings: {
|
|
number_of_shards: 1,
|
|
similarity: {
|
|
scripted_tfidf: {
|
|
type: "scripted",
|
|
script: {
|
|
source:
|
|
"double tf = Math.sqrt(doc.freq); double idf = Math.log((field.docCount+1.0)/(term.docFreq+1.0)) + 1.0; double norm = 1/Math.sqrt(doc.length); return query.boost * tf * idf * norm;",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
mappings: {
|
|
properties: {
|
|
field: {
|
|
type: "text",
|
|
similarity: "scripted_tfidf",
|
|
},
|
|
},
|
|
},
|
|
});
|
|
console.log(response);
|
|
|
|
const response1 = await client.index({
|
|
index: "index",
|
|
id: 1,
|
|
document: {
|
|
field: "foo bar foo",
|
|
},
|
|
});
|
|
console.log(response1);
|
|
|
|
const response2 = await client.index({
|
|
index: "index",
|
|
id: 2,
|
|
document: {
|
|
field: "bar baz",
|
|
},
|
|
});
|
|
console.log(response2);
|
|
|
|
const response3 = await client.indices.refresh({
|
|
index: "index",
|
|
});
|
|
console.log(response3);
|
|
|
|
const response4 = await client.search({
|
|
index: "index",
|
|
explain: "true",
|
|
query: {
|
|
query_string: {
|
|
query: "foo^1.7",
|
|
default_field: "field",
|
|
},
|
|
},
|
|
});
|
|
console.log(response4);
|
|
----
|