I have a Json object
const mainString = {
bool: {
should: [{
nested: {
path: "employee",
query: {
bool: {
must: [NAME_QUERIES]
}
}
}
}, NICK_NAME_QUERIES],
minimum_should_match: 1
}
}
where NAME_QUERIES and NICK_NAME_QUERIES are json object and is input from user.
for example:
NAME_QUERIES = [{
multi_match: {
query: "fname1 lname1",
fields: ["employee.name"],
type: "phrase"
}
}, {
multi_match: {
query: "fname2 lname2",
fields: ["employee.name"],
type: "phrase"
}
}]
NICK_NAME_QUERIES = [{
multi_match: {
query: "fname1 lname1",
fields: ["employee.nickName"],
type: "phrase"
}
}, {
multi_match: {
query: "fname2 lname2",
fields: ["employee.nickName"],
type: "phrase"
}
}]
How can i replace NAME_QUERIES and NICK_NAME_QUERIES in mainString ?
I want o/p of mainString like below
{
bool: {
should: [{
nested: {
path: "employee",
query: {
bool: {
must: [{
multi_match: {
query: "fname1 lname1",
fields: ["employee.name"],
type: "phrase"
}
}, {
multi_match: {
query: "fname2 lname2",
fields: ["employee.name"],
type: "phrase"
}
}]
}
}
}
}, {
multi_match: {
query: "fname1 lname1",
fields: ["employee.nickName"],
type: "phrase"
}
}, {
multi_match: {
query: "fname2 lname2",
fields: ["employee.nickName"],
type: "phrase"
}
}],
minimum_should_match: 1
}
}
NAME_QUERIES can contain N number of multi_match’s, just added 2 for above example
I tried to directly add NAME_QUERIES and NICK_NAME_QUERIES in the string, but it adds [] .
Also I tried to use jsonStringify and then used the variable, then it added for all the fields double quotes like (“multi_match”) where as i want for keys no quotes.
Is there any simple way to replace them without [] in the main string ?

