I'm using elasticsearch 7.13.3 and I want to call the put index template API from my typescript app. I'm using the package "#elastic/elasticsearch": "7.13.0" but I get error for the composition of the call.
From kibana I can execute without any error:
PUT _component_template/template-xxx2
{
"template": {
"mappings": {
"properties": {
"#timestamp": {
"type": "date"
},
"id": {
"type": "keyword"
},
"value": {
"type": "double",
"coerce": false
}
}
}
}
}
PUT _index_template/index-template-xxx2
{
"index_patterns": ["template-xxx2*"],
"template": {
"settings": {
"number_of_shards": 2
},
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
"mydata": { }
}
},
"priority": 600,
"composed_of": ["template-xxx2"],
"version": 3,
"_meta": {
"description": "template-xxx2 description"
}
}
and I want do the same from my node app.
The template creation it's ok:
void this.db.clientDb.indices.putTemplate({
name: `template_${this.index}`,
body: {
mappings: {
properties: {
'#timestamp': {
type: 'date'
},
id: {
type: 'keyword'
},
value: {
type: 'double',
coerce: false
}
}
}
}
});
But I can't find the correct overload for the this.db.clientDb.indices.putIndexTemplate({ API.
This gave me errors: (no overloads match this call)
void this.db.clientDb.indices.putIndexTemplate({
name: '',
index_patterns: ["template-xxx2*"], // --> where should I put this property?
body: {
settings: {
number_of_shards: 2
},
mappings: {
_source: {
enabled: true
}
},
aliases: {
mydata: {}
}
},
priority: 500,
composed_of: ['template-xxx2'], // --> where should I put this property?
version: 3,
_meta: {
description: 'template-xxx2 description'
}
});
I want to do this latest script.
Index templates have been overhauled in 7.8. The previous legacy endpoint was called _template and the new one is called _index_template.
You're mixing calls to the old and the new endpoint, i.e. putTemplate calls the old legacy endpoint and putIndexTemplate calls the new one.
Moreover, the whole template definition needs to go inside body, not at the top level of the call parameters.
So here is what you need to do. First, make this call to store the component template:
void this.db.clientDb.cluster.putComponentTemplate({
"name": "template-xxx2",
"body": {
"template": {
"mappings": {
"properties": {
"#timestamp": {
"type": "date"
},
"id": {
"type": "keyword"
},
"value": {
"type": "double",
"coerce": false
}
}
}
}
}
})
Then store the index template with the following call:
void this.db.clientDb.indices.putIndexTemplate({
"name": "index-template-xxx2",
"body": {
"index_patterns": ["template-xxx2*"],
"template": {
"settings": {
"number_of_shards": 2
},
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
"mydata": { }
}
},
"priority": 600,
"composed_of": ["template-xxx2"],
"version": 3,
"_meta": {
"description": "template-xxx2 description"
}
}
})
Related
I'm currently facing an issue with my datatable implemented in ReactJS. I'm retrieving data from elasticsearch and populating the datatable with it. The data retrieval process works fine without the filter applied, however, when I apply filters to the data, the datatable remains empty, even though the data _source has matching records.
The structure of the parameters I am sending is as follows:
{
pageIndex: 1,
pageSize: 10,
sort: { order: '', key: '' },
query: '',
filterData: {
analysis: [ '0', '1', '2', '3' ],
threat_level_id: [ '1', '2', '3', '4' ],
}
}
EndPoint:
POST /api/v1/events/public/list
Controller:
exports.getPublicEvents = async (req, res) => {
try {
client.ping()
const { pageIndex, pageSize, sort, query, filterData } = req.body
let esQuery = {
index: 'ns_*',
body: {
query: {
bool: {
must: [
{
match_all: {},
},
],
filter: [],
},
},
from: (pageIndex - 1) * pageSize,
size: pageSize,
},
}
if (query) {
esQuery.body.query.bool.must = [
{
match: {
'Event.info': {
query: query,
fuzziness: 'AUTO',
},
},
},
]
}
if (filterData.analysis.length > 0) {
esQuery.body.query.bool.filter.push({
terms: {
'Event.analysis': filterData.analysis,
},
})
}
if (filterData.threat_level_id.length > 0) {
esQuery.body.query.bool.filter.push({
terms: {
'Event.threat_level_id': filterData.threat_level_id,
},
})
}
let esResponse = await client.search(esQuery)
let data = esResponse.hits.hits.map((hit) => hit._source)
let total = esResponse.hits.total.value
res.status(200).json({
status: 'success',
data: data,
total: total,
})
} catch (error) {
res.status(500).json({
error: 'Error connecting to Elasticsearch',
errorMessage: error.message,
})
}
}
The controller below is without filters and it works just fine.
exports.getPublicEvents = async (req, res) => {
try {
client.ping()
const { pageIndex, pageSize, sort, query } = req.body
let esQuery = {
index: 'ns_*',
body: {
query: {
match_all: {},
},
from: (pageIndex - 1) * pageSize,
size: pageSize,
},
}
if (query) {
esQuery.body.query = {
match: {
'Event.info': {
query: query,
fuzziness: 'AUTO',
},
},
}
}
let esResponse = await client.search(esQuery)
let data = esResponse.hits.hits.map((hit) => hit._source)
let total = esResponse.hits.total.value
res.status(200).json({
status: 'success',
data: data,
total: total,
})
} catch (error) {
res.status(500).json({
error: 'Error connecting to Elasticsearch',
errorMessage: error.message,
})
}
}
ElasticSearech version: 7.17.8
Result of: console.log(JSON.stringify(esQuery))
{
"index": "INDEX_NAME",
"body": {
"query": {
"bool": {
"must": [{ "match_all": {} }],
"filter": [
{ "terms": { "Event.analysis": ["0", "1", "2"] } },
{ "terms": { "Event.threat_level_id": ["1", "2", "3", "4"] } }
]
}
},
"from": 0,
"size": 10
}
}
Data in elascticsearch schema
{
"#version": "1",
"#timestamp": "2023-02-01T14:43:09.997Z",
"Event": {
"info": ".......................",
"description": ".......................",
"analysis": 0,
"threat_level_id": "4",
"created_at": 1516566351,
"uuid": "5a64f74f0e543738c12bc973322",
"updated_at": 1675262417
}
}
Index Mapping
{
"index_patterns": ["INDEX_NAME"],
"template": "TEMPLATE_NAME",
"settings": {
"number_of_replicas": 0,
"index.mapping.nested_objects.limit": 10000000
},
"mappings": {
"dynamic": false,
"properties": {
"#timestamp": {
"type": "date"
},
"Event": {
"type": "nested",
"properties": {
"date_occured": {
"type": "date"
},
"threat_level_id": {
"type": "integer"
},
"description": {
"type": "text"
},
"is_shared": {
"type": "boolean"
},
"analysis": {
"type": "integer"
},
"uuid": {
"type": "text"
},
"created_at": {
"type": "date"
},
"info": {
"type": "text"
},
"shared_with": {
"type": "nested",
"properties": {
"_id": {
"type": "text"
}
}
},
"updated_at": {
"type": "date"
},
"author": {
"type": "text"
},
"Attributes": {
"type": "nested",
"properties": {
"data": {
"type": "text"
},
"type": {
"type": "text"
},
"uuid": {
"type": "text"
},
"comment": {
"type": "text"
},
"category": {
"type": "text"
},
"value": {
"type": "text"
},
"timestamp": {
"type": "date"
}
}
},
"organisation": {
"type": "nested",
"properties": {
"name": {
"type": "text"
},
"uuid": {
"type": "text"
}
}
},
"Tags": {
"type": "nested",
"properties": {
"color": {
"type": "text"
},
"name": {
"type": "text"
}
}
},
"TLP": {
"type": "nested",
"properties": {
"color": {
"type": "text"
},
"name": {
"type": "text"
}
}
}
}
}
}
}
}
Event is a nested field, so you need to use nested queries, like this:
{
"index": "INDEX_NAME",
"body": {
"query": {
"bool": {
"must": [{ "match_all": {} }],
"filter": [
{
"nested": {
"path": "Event",
"query": {"terms": { "Event.analysis": ["0", "1", "2"] }}
}
},
{
"nested": {
"path": "Event",
"query": {"terms": { "Event.threat_level_id": ["1", "2", "3", "4"] }}
}
}
]
}
},
"from": 0,
"size": 10
}
}
Current, I use #/components/responses/Default response as reuseable properties for all api defines. But some API need to add more a field but not change default response format. So Can I reUse default response and add more field for response
{
"openapi": "3.0.3",
"path": {
"/login": {
"post": {
"responses": {
200: {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/responses/defaultResponse"
}
}
}
}
}
}
}
},
"components": {
"schemas" :{
"responseSchema": {
"type": "object",
"properties": {
"httpCode": { "type": "integer" },
"message": { "type": "string" }
}
}
},
"responses": {
"defaultResponse": { "$ref": "#/components/schemas/responseSchema" }
}
}
}
Above is my swagger spec. but with Login, if success I want to put more a field (token) to return token for client, Can I do it with this or have to manual define schema ?
In OpenAPI version 3, you do this with the allOf keyword. Detail document
{
"openapi": "3.0.3",
"info": {
"title": "Example",
"version": "1.0"
},
"paths": {
"/login": {
"post": {
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/responses/defaultResponse"
},
{
"type": "object",
"properties": {
"token": {
"type": "string"
}
}
}
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"responseSchema": {
"type": "object",
"properties": {
"httpCode": {
"type": "integer"
},
"message": {
"type": "string"
}
}
}
},
"responses": {
"defaultResponse": {
"$ref": "#/components/schemas/responseSchema"
}
}
}
}
I'm converting a Sdmx xml api output to an Json Object. I try with boot 'xml-js' and 'xml2js' and
the result is a complex object like this:
{
"_declaration": {
"_attributes": {
"version": "1.0",
"encoding": "utf-8"
}
},
"_comment": "NSI Web Service v6.16.0",
"message:Structure": {
"_attributes": {
"xmlns:message": "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message",
"xmlns:structure": "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure",
"xmlns:common": "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common"
},
"message:Header": {
"message:ID": {
"_text": "IDREF161"
},
"message:Test": {
"_text": "false"
},
"message:Prepared": {
"_text": "2021-04-11T13:21:40.0658418+02:00"
},
"message:Sender": {
"_attributes": {
"id": "Unknown"
}
},
"message:Receiver": {
"_attributes": {
"id": "Unknown"
}
}
},
"message:Structures": {
"structure:Codelists": {
"structure:Codelist": {
"_attributes": {
"id": "CL_CAUSEMORTE_SL",
"urn": "urn:sdmx:org.sdmx.infomodel.codelist.Codelist=IT1:CL_CAUSEMORTE_SL(1.1)",
"agencyID": "IT1",
"version": "1.1",
"isFinal": "true"
},
"common:Name": [
{
"_attributes": {
"xml:lang": "it"
},
"_text": "Cause di morte - European short list"
},
{
"_attributes": {
"xml:lang": "en"
},
"_text": "European short list of causes of death"
}
],
I can't navigate the structure and retrive elements value in anyway, examples:
console.log(result['message:Structure']);
undefined
console.log(result[2]);
undefined
any help is appreciated,
regards, Maurizio
I'm using JSON descriptors instead of proto format. Everithing works, unless the array of Todo. I need an array of Todos.
How define that? I put the "type": "array", but always return the error:
'Error: no such Type or Enum 'array' in Type .Todos'
My json file is like this:
const todo = {
"nested": {
"Services": {
"methods": {
"createTodo": {
"requestType": "Todo",
"requestStream": false,
"responseType": "Todo",
"responseStream": false
},
"readTodos": {
"requestType": "voidNoParam",
"requestStream": false,
"responseType": "Todos",
"responseStream": false
},
"readTodosStream": {
"requestType": "voidNoParam",
"requestStream": false,
"responseType": "Todo",
"responseStream": true
}
}
},
"Todo": {
"fields": {
"id": {
"type": "int32",
"id": 1
},
"text": {
"type": "string",
"id": 2
}
}
},
"Todos": {
"fields": {
"items": {
"type": "array",
"id": 1
}
}
},
"voidNoParam": {
"fields": {}
}
}
}
module.exports = todo
I found the problem, really simple.
"Todos": {
"fields": {
"items": {
"rule": "repeated",
"type": "Todo",
"id": 1
}
}
},
Automating creation of Sales Invoice via Rest API
Unable to get CustomerLocation to populate
In the WebService EndPoint the Mapped Object and Mapped Fields are blank for this item
Has any one successfully used this API to modify Location?
Does any one know if I have a formatting error in my JSON for Linked Entities, it matches the documentation but may not be up to date?
Tried several formats of JSON based on the guide and experience including Linked, Summary, Custom and Detail
Tried both BillToSettings and BillingSetting Entities
Searched Known issues, Newton JSon
"Type": { "value": "Invoice" },
"CustomerID": { "value": "C0004055" },
/// bit does not create in Acumatica
"BillToSettings": { "CustomerLocation": { "value": "67217" } },
/// "BillingSettings" : {"CustomerLocation" : {"value" : "67217"}
/// also LocationID, CustomerLocationID and many combinations there of
"CustomerOrder": { "value": 1942 },
"Date": { "value": "2/14/2019" },
"Description": { "value": "SO S048773" },
"Details": [
{
"InventoryID": { "value": "POLLING-HOSTING" },
"TransactionDescr": { "value": "GPRS Monitoring" },
"UOM": { "value": "PNTS" },
"Qty": { "value": "3" },
"UnitPrice": { "value": "68.25" }
},
{
"InventoryID": { "value": "AIRTIME" },
"TransactionDescr": { "value": "GPRS Airtime" },
"UOM": { "value": "EACH" },
"Qty": { "value": "3" },
"UnitPrice": { "value": "20" }
}
]
I expect the Default MAIN location to be overridden with 67217 instead every record shows main
If I add the address Override fields (as below) then I get data for them on the successful creation of the invoice but no CustomerLocation data is returned.
Nor does the LocationID update correctly
BillingSettings = new
{
BillToAddressOverride = new {value = true},
BillToContactOverride = new { value = true },
CustomerLocation = new { value = "67217"}
},
I tried to use your JSON example on a clean SalesDemo install of 2019R1 and could replicate the same issue that you're experiencing.
I think it has to do with the CustomerLocation field not being mapped in the Default 18.200.001 endpoint. It actually makes sense if we look at the response object - there is no CustomerLocation field in the response either.
First Attempt, without extending the API endpoint:
{
"Type": {
"value": "Invoice"
},
"CustomerID": {
"value": "ABARTENDE"
},
"Date": {
"value": "5/10/2019"
},
"Description": {
"value": "Test SalesInvoice Creation"
},
"BillingSettings" : {
"CustomerLocation" : {
"value" : "VEGAS"
}
}
}
Response from the first attempt:
"BillingSettings": {
"BillToAddress": {
"AddressLine1": {
"value": "201 Lower Notch Rd"
},
"AddressLine2": {},
"City": {
"value": "Little Falls"
},
"Country": {
"value": "US"
},
"PostalCode": {
"value": "07424"
},
"State": {
"value": "NJ"
}
},
"BillToAddressOverride": {
"value": false
},
"BillToContact": {
"Attention": {
"value": "Accounts Receivable"
},
"BusinessName": {
"value": "USA Bartending School"
},
"Email": {
"value": "barkeep#usabartend.con"
},
"Phone1": {
"value": "+1 (908) 532-9522"
}
},
"BillToContactOverride": {
"value": false
}
}
If you extend the endpoint and implement the Location field which can be found under the Invoice Summary selection when populating the field, you should be able to achieve your intended outcome. PS. I added the Location on the SalesInvoice object itself, and not on the BillingSettings object:
Second Request, the extended endpoint includes the Location field that was added:
{
"Type": {
"value": "Invoice"
},
"CustomerID": {
"value": "ABARTENDE"
},
"Date": {
"value": "5/10/2019"
},
"Description": {
"value": "Test SalesInvoice Creation"
},
"Location" : {
"value" : "VEGAS"
}
}
Second Response:
{
"Amount": {
"value": 0
},
"Balance": {
"value": 0
},
"BillingSettings": {
"BillToAddressOverride": {
"value": false
},
"BillToContactOverride": {
"value": false
}
},
"Currency": {
"value": "USD"
},
"CustomerID": {
"value": "ABARTENDE"
},
"Date": {
"value": "2019-05-10T00:00:00+00:00"
},
"Description": {
"value": "Test SalesInvoice Creation"
},
"DueDate": {
"value": "2019-06-09T00:00:00+02:00"
},
"Hold": {
"value": false
},
"Location": {
"value": "VEGAS"
},
"ReferenceNbr": {
"value": "AR006994"
},
"Status": {
"value": "Balanced"
},
"Type": {
"value": "Invoice"
}
}
As to whether the CustomerLocation holds any meaningful value/purpose, I'm not sure, so I left it in the BillingSettings as is.