I have a listing object with filters. I need to create an aggregation to filter the listings based on filters.
This is a listing object example
[
{
"_id": "5c484ec4cb1e150b1efce101",
"details": {
"title": "Villa 1",
"description": "Description about Villa 1"
},
"options": {
"features": [
"5c482b1ff9f18807694040c6",
"5c482b2ef9f18807694040c7",
"5c482b3af9f18807694040c8",
"5c482b49f9f18807694040c9"
],
"filters": [
{
"filter": "5c482c2c2abe2f07ccd5d428",
"value": 7
},
{
"filter": "5c482c392abe2f07ccd5d429",
"value": 3
},
{
"filter": "5c482c462abe2f07ccd5d42a",
"value": 5
},
{
"filter": "5c482c4d2abe2f07ccd5d42b",
"value": 2
},
{
"filter": "5c482c562abe2f07ccd5d42c",
"value": true
},
{
"filter": "5c482c612abe2f07ccd5d42d",
"value": true
}
]
},
"memberOnly": false,
"feature": false,
"active": true,
"Category": "5c45af3b5ccf2c20833a547a"
},
{
"_id": "5c484ec4cb1e150b1efce101",
"details": {
"title": "Villa 2",
"description": "Description about Villa 2"
},
"options": {
"features": [
"5c482b1ff9f18807694040c6",
"5c482b2ef9f18807694040c7",
"5c482b3af9f18807694040c8",
"5c482b49f9f18807694040c9"
],
"filters": [
{
"filter": "5c482c2c2abe2f07ccd5d428",
"value": 5
},
{
"filter": "5c482c392abe2f07ccd5d429",
"value": 7
},
{
"filter": "5c482c462abe2f07ccd5d42a",
"value": 2
},
{
"filter": "5c482c4d2abe2f07ccd5d42b",
"value": 6
},
{
"filter": "5c482c562abe2f07ccd5d42c",
"value": true
},
{
"filter": "5c482c612abe2f07ccd5d42d",
"value": true
}
]
},
"memberOnly": false,
"feature": false,
"active": true,
"Category": "5c45af3b5ccf2c20833a547a"
}
]
I need a mongoose aggregation to be able to filter between objects based on the filter and its value
example:
i need to filter listings that have
filter "5c482c2c2abe2f07ccd5d428" with a value $gte:4
filter "5c482c4d2abe2f07ccd5d42b" with a value $gte:3
filter "5c482c612abe2f07ccd5d42d" with a true value
When I filter the expected result should be
[
{
"_id": "5c484ec4cb1e150b1efce101",
"details": {
"title": "Villa 1",
"description": "Description about Villa 1"
},
"options": {
"features": [
"5c482b1ff9f18807694040c6",
"5c482b2ef9f18807694040c7",
"5c482b3af9f18807694040c8",
"5c482b49f9f18807694040c9"
],
"filters": [
{
"filter": "5c482c2c2abe2f07ccd5d428",
"value": 7
},
{
"filter": "5c482c392abe2f07ccd5d429",
"value": 3
},
{
"filter": "5c482c462abe2f07ccd5d42a",
"value": 5
},
{
"filter": "5c482c4d2abe2f07ccd5d42b",
"value": 2
},
{
"filter": "5c482c562abe2f07ccd5d42c",
"value": true
},
{
"filter": "5c482c612abe2f07ccd5d42d",
"value": true
}
]
},
"memberOnly": false,
"feature": false,
"active": true,
"Category": "5c45af3b5ccf2c20833a547a"
}
]
the solution was
Listing.find({
$and: [{
'options.filters': {
$elemMatch: {
filter: this.mongoose.Types.ObjectId('5c482c2c2abe2f07ccd5d428'),
value: {$gte: 4}
}
}
}, {
'options.filters': {
$elemMatch: {
filter: this.mongoose.Types.ObjectId('5c482c4d2abe2f07ccd5d42b'),
value: {$gte: 3}
}
}
}, {
'options.filters': {
$elemMatch: {
filter: this.mongoose.Types.ObjectId('5c482c612abe2f07ccd5d42d'),
value: true
}
}
});
Related
Problem:
I need to only update one document in the spots available array that has an id of "empty". My previous query was updating all matching sub documents with "empty" as the id; which is no good Example Below. So I decided to use aggregation so that I could add a limit stage so that I could only update one item, but come to find out I cannot update the original document with an aggregation. This leaves the only option to use an array filter that only updates one/first of its matches. Is this possible? I feel like there has to be a way to only update one match on an array filter and if there isn't this is definitely something that should be added.
My code:
This code updates every object with "empty"
const client = await clientPromise;
const db = client.db();
// const query = db.collection('events').aggregate(agg);
const query = await db.collection('events').updateOne({
_id: new ObjectId("6398c34ca67dbe3286452f23"),
createdBy: new ObjectId("636c1778f1d09191074f9690"),
"weights.weight": 12
},
{
$set: {
"weights.$.spotsAvailable.$[el2]": {
"name": "Wayne Wrestler",
"userId": new ObjectId("636c1778f1d09191074f9690")
}
}
},
{
arrayFilters: [{ "el2": { "userId": "empty" } }]
})
Example documents:
Event:
{
"_id": {
"$oid": "6398c34ca67dbe3286452f23"
},
"name": "test",
"createdBy": {
"$oid": "636c1778f1d09191074f9690"
},
"description": "testing",
"date": {
"$date": {
"$numberLong": "1645488000000"
}
},
"location": {
"type": "Point",
"coordinates": [
0,
0
]
},
"weights": [
{
"spotsAvailable": [
{
"name": "empty",
"userId": "empty"
},
{
"name": "empty",
"userId": "empty"
},
{
"name": "empty",
"userId": "empty"
}
],
"weight": 12
},
{
"spotsAvailable": [
{
// only one of these should've been updated, but both were
"name": "Wayne Wrestler",
"userId": {
"$oid": "636c1778f1d09191074f9690"
}
},
{
"name": "Wayne Wrestler",
"userId": {
"$oid": "636c1778f1d09191074f9690"
}
}
],
"weight": 15
}
],
"eventApplicants": [
{
"userId": {
"$oid": "636c1778f1d09191074f9690"
},
"name": "Wayne Wrestler",
"weight": 12
}
]
}
User:
{
"_id": {
"$oid": "636c1778f1d09191074f9690"
},
"name": "Wayne Wrestler",
"email": "wakywayne80#gmail.com",
"image": "https://lh3.googleusercontent.com/a/ALm5wu32gXjDIRxncjjQA9I4Yl-sjFH5EWsTlmvdM_0kiw=s96-c",
"emailVerified": {
"$date": {
"$numberLong": "1670864727212"
}
},
"createdEvents": [
{
"createdEventName": "test",
"createdEventDate": {
"$date": {
"$numberLong": "1645488000000"
}
},
"createdEventDescription": "testing",
"createdEventWeights": [
{
"weight": "12",
"filled": [
false,
false,
false
]
},
{
"weight": "15",
"filled": [
false,
false
]
}
],
"createdEventId": {
"$oid": "6398c34ca67dbe3286452f23"
}
}
],
"userSignedUpEvents": [],
"availableWeights": [
1,
123
],
"signedUpEvents": [
{
"eventId": {
"$oid": "636c722f67642c30dc5ffc30"
},
"eventName": "Utah",
"eventDate": {
"$date": {
"$numberLong": "1667913330000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "636c722f67642c30dc5ffc30"
},
"eventName": "Utah",
"eventDate": {
"$date": {
"$numberLong": "1667913330000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "637ec484ac2d675b30590b47"
},
"eventName": "Maybe?",
"eventDate": {
"$date": {
"$numberLong": "1672272000000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "636c722f67642c30dc5ffc30"
},
"eventName": "Utah",
"eventDate": {
"$date": {
"$numberLong": "1667913330000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "638d5274628db2a7bf61df49"
},
"eventName": "Eva's",
"eventDate": {
"$date": {
"$numberLong": "1698019200000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "636c722f67642c30dc5ffc30"
},
"eventName": "Utah",
"eventDate": {
"$date": {
"$numberLong": "1667913330000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "6398a922abb5c168ede595fb"
},
"eventName": "Nikko's event",
"eventDate": {
"$date": {
"$numberLong": "1670976000000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "6398a922abb5c168ede595fb"
},
"eventName": "Nikko's event",
"eventDate": {
"$date": {
"$numberLong": "1670976000000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "6398c34ca67dbe3286452f23"
},
"eventName": "test",
"eventDate": {
"$date": {
"$numberLong": "1645488000000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "6398c34ca67dbe3286452f23"
},
"eventName": "test",
"eventDate": {
"$date": {
"$numberLong": "1645488000000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "6398c34ca67dbe3286452f23"
},
"eventName": "test",
"eventDate": {
"$date": {
"$numberLong": "1645488000000"
}
},
"accepted": false
},
{
"eventId": {
"$oid": "6398c34ca67dbe3286452f23"
},
"eventName": "test",
"eventDate": {
"$date": {
"$numberLong": "1645488000000"
}
},
"accepted": false
}
]
}
I have tried:
Pluging in variables without the new ObjectId syntax
Plugin in variables with the new ObjectId syntax
Using the exact same hardcoded values that I got from copying the aggregation code from compass for the node driver
All of these either don't work or result in every subdocument with "empty" getting filled
One option is to use update with pipeline:
Since this is a double nested array, it is easier to do it in two steps - internal and external
First create the "external" item to replace in weights array and call it newItem. It is calculated using $reduce which allow us to manipulate the internal array while looping on it.
Replace the relevant item on weights array with our newItem using $map with $cond
db.collection.update(
{_id: ObjectId("6398c34ca67dbe3286452f23"), "weights.weight": 12},
[
{$set: {
newItem: {$reduce: {
input: {$getField: {
input: {$first: {
$filter: {
input: "$weights",
as: "item",
cond: {$eq: ["$$item.weight", 12]}
}
}},
field: "spotsAvailable"
}},
initialValue: [],
in: {$concatArrays: [
"$$value",
{$cond: [
{$and: [
{$eq: ["$$this.userId", "empty"]},
{$not: {$in: [ObjectId("636c1778f1d09191074f9690"), "$$value.userId"]}}
]},
[{
name: "Wayne Wrestler",
userId: ObjectId("636c1778f1d09191074f9690")
}],
["$$this"]
]}
]}
}}
}},
{$set: {
weights: {$map: {
input: "$weights",
in: {$cond: [
{$eq: ["$$this.weight", 12]},
{$mergeObjects: [
"$$this",
{spotsAvailable: "$newItem"}
]},
"$$this"
]}
}},
newItem: "$$REMOVE"
}}
])
See how it works on the playground example
You can first $unwind the weights for easier processing first. Use $reduce to iterate through the weights.spotsAvailable array and use a compound object to store the result and a flag to indicate whether it is updated or not. Finally use the result to $merge back to the original document.
db.collection.aggregate([
{
$match: {
"_id": ObjectId("6398c34ca67dbe3286452f23"),
createdBy: ObjectId("636c1778f1d09191074f9690"),
"weights.weight": 12,
"weights.spotsAvailable.userId": "empty"
}
},
{
"$unwind": "$weights"
},
{
"$addFields": {
"results": {
"$reduce": {
"input": "$weights.spotsAvailable",
"initialValue": {
result: [],
updated: false
},
"in": {
"$cond": {
"if": {
$and: [
{
$eq: [
false,
"$$value.updated"
]
},
{
$eq: [
"empty",
"$$this.userId"
]
}
]
},
"then": {
result: {
"$concatArrays": [
"$$value.result",
[
{
"name": "Wayne Wrestler",
"userId": ObjectId("636c1778f1d09191074f9690")
}
]
]
},
updated: true
},
"else": {
result: {
"$concatArrays": [
"$$value.result",
[
"$$this"
]
]
},
updated: "$$value.updated"
}
}
}
}
}
}
},
{
$set: {
"weights.spotsAvailable": "$results.result",
"results": "$$REMOVE"
}
},
{
$group: {
_id: "$_id",
"name": {
$first: "$name"
},
"createdBy": {
$first: "$createdBy"
},
"description": {
$first: "$description"
},
"date": {
$first: "$date"
},
"location": {
$first: "$location"
},
"weights": {
$push: "$weights"
},
"eventApplicants": {
$first: "$eventApplicants"
}
}
},
{
"$merge": {
"into": "collection",
"on": "_id"
}
}
])
Mongo Playground
Hey I have a problem with my mongoDb search. I need to add one more index to my search for better result. But since its not in mappings whenever i perform my search as following it returns me nothing.
`
embeddedDocument: {
path: 'produces',
operator: {
compound: {
"must": [
{
autocomplete: {
"path": "produces.name",
"query": val,
"fuzzy": {
"maxEdits": 2,
"prefixLength": 3
}
}
},
{
equals: { path: 'produces.deleted', value: false }
}
],
}
}
}
and here is my index definition
{
"mappings": {
"dynamic": false,
"fields": {
"companyName": [
{
"analyzer": "lucene.standard",
"type": "string"
},
{
"foldDiacritics": true,
"maxGrams": 6,
"minGrams": 2,
"tokenization": "edgeGram",
"type": "autocomplete"
}
],
"produces": {
"type": "embeddedDocuments",
"fields": {
"name": [
{
"analyzer": "lucene.standard",
"type": "string"
},
{
"foldDiacritics": true,
"maxGrams": 6,
"minGrams": 2,
"tokenization": "edgeGram",
"type": "autocomplete"
}
]
}
},
"status": {
"type": "string"
}
}
}
}
So i need to update my index definition as following.
{
"mappings": {
"dynamic": false,
"fields": {
"companyName": [
{
"analyzer": "lucene.standard",
"type": "string"
},
{
"foldDiacritics": true,
"maxGrams": 6,
"minGrams": 2,
"tokenization": "edgeGram",
"type": "autocomplete"
}
],
"produces": {
"type": "embeddedDocuments",
"fields": {
"deleted": {
"type": "boolean"
},
"name": [
{
"analyzer": "lucene.standard",
"type": "string"
},
{
"foldDiacritics": true,
"maxGrams": 6,
"minGrams": 2,
"tokenization": "edgeGram",
"type": "autocomplete"
}
]
}
},
"status": {
"type": "string"
}
}
}
}
`
But my problem is i dont know where to add this index definition on the mongoDB side so i can filter with deleted false criteria.
I tried to add index to mongoDB to produces collection but it doesnt work and i still get empty result.
Need to get a list of all accounts by section and the net total of the debit and credit values. For example:
Section:Revenue
ACC Income: $10,000
Other Income: $5,000
Section Expenses
Advertising: 100
Rent: 20,000
I have used a for...in loop but only get down to the object of the array. I know I need to loop within a loop but I don't know how to. Have been trying for 2wks now and still only get down to the Section, not the accounts and values.
{
"cashtb": {
"response": {
"statusCode": 200,
"body": {
"reports": [
{
"reportID": "TrialBalance",
"reportName": "Trial Balance",
"reportType": "TrialBalance",
"reportTitles": [
"Trial Balance",
"Test Org",
"As at 1 July 2022"
],
"reportDate": "27 September 2022",
"rows": [
{
"rowType": "Header",
"cells": [
{
"value": "Account"
},
{
"value": "Debit"
},
{
"value": "Credit"
},
{
"value": "YTD Debit"
},
{
"value": "YTD Credit"
}
]
},
{
"rowType": "Section",
"title": "Revenue",
"rows": [
{
"rowType": "Row",
"cells": [
{
"value": "ACC Income (191)",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "0.00",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "13456.25",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
}
]
},
{
"rowType": "Row",
"cells": [
{
"value": "Eftpos Surcharge Income (193)",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "82.61",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "3304.29",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
}
]
},
{
"rowType": "Row",
"cells": [
{
"value": "Subcontractor Income (192)",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "1086.96",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "10088.15",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
}
]
}
]
},
{
"rowType": "Section",
"title": "Expenses",
"rows": [
{
"rowType": "Row",
"cells": [
{
"value": "Advertising (301)",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "0.00",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "1968.40",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
}
]
}]}]}]}}}}
I used this code but it only goes to sectione and returns row heading but not the values in the object like account or debit/credit values
let cellstrip = cashtbarray.Reports[0].Rows;
for(let i=0, len=cellstrip.length; i<len; i++){
for (let valuestrip in cellstrip[i]){
console.log(valuestrip, cellstrip[i]
[valuestrip]);
}
}
//you can put another loop in here that starts with
“j” - e.g.
for(let j=0, len=valuestrip.length; j<len; j++){
for (let accountsstrip in valuestrip.Rows[0].Cells[cashtbarray.Reports[0].Rows[k]
.Rows[l].Cells.length - 3].Value !== ''){
//Do something which each value
var accountvalue = accountsstrip;
console.log(accountvalue);
}
}
Including them in the Attribute collection of a Stock Item doesn't seem to work -- even if I make sure the attribute ids already exist in the db. When I do the PUT request, the rest of the data in the record is inserted, but not the attributes. The response even returns an empty attribute array instead of what I sent to it.
Do I need to extend the API for this to work? If so, does anyone have any examples? I haven't been able to find any yet.
The request is:
http://localhost/acum172100034/entity/Default/17.200.001/StockItem
The body is:
{
"InventoryID": {
"value": "RGTONYIT166"
},
"Attributes": [
{
"AttributeID": {
"value": "Item Attribute"
},
"Value": {
"value": "2"
}
}
]
}
The PUT response is:
{
"id": "665e403c-d310-4bb4-9759-e2487dd5abc7",
"rowNumber": 1,
"note": null,
"ABCCode": {},
"Attributes": [],
"AutoIncrementalValue": {},
"AverageCost": {
"value": 0
},
"BaseUOM": {
"value": "EA"
},
"COGSAccount": {
"value": "50000"
},
"COGSSubaccount": {
"value": "CON000"
},
"Content": {},
"CurrentStdCost": {
"value": 0
},
"DefaultIssueLocationID": {
"value": "R1S1"
},
"DefaultPrice": {
"value": 0
},
"DefaultReceiptLocationID": {
"value": "RECEIVING"
},
"DefaultWarehouseID": {
"value": "WHOLESALE"
},
"DeferralAccount": {},
"DeferralSubaccount": {},
"Description": {
"value": "tonyitem166 - blah blah 2"
},
"DimensionVolume": {
"value": 3
},
"DimensionWeight": {
"value": 2
},
"DiscountAccount": {},
"DiscountSubaccount": {},
"ImageUrl": {},
"InventoryAccount": {
"value": "12100"
},
"InventoryID": {
"value": "RGTONYIT166"
},
"InventorySubaccount": {
"value": "CON000"
},
"IsAKit": {
"value": false
},
"ItemClass": {
"value": "CONSUMER 200FITNESS"
},
"ItemStatus": {
"value": "Active"
},
"ItemType": {
"value": "Finished Good"
},
"LandedCostVarianceAccount": {
"value": "52400"
},
"LandedCostVarianceSubaccount": {
"value": "CON000"
},
"LastCost": {
"value": 0
},
"LastModified": {
"value": "2018-10-02T17:13:38.707-04:00"
},
"LastStdCost": {
"value": 0
},
"LotSerialClass": {
"value": "NOTTRACKED"
},
"Markup": {
"value": 0
},
"MaxCost": {
"value": 0
},
"MinCost": {
"value": 0
},
"MinMarkup": {
"value": 0
},
"MSRP": {
"value": 0
},
"PackagingOption": {
"value": "Manual"
},
"PackSeparately": {
"value": false
},
"PendingStdCost": {
"value": 0
},
"POAccrualAccount": {
"value": "20100"
},
"POAccrualSubaccount": {
"value": "CON000"
},
"PostingClass": {
"value": "CON"
},
"PriceClass": {},
"PriceManager": {},
"PriceWorkgroup": {},
"ProductManager": {},
"ProductWorkgroup": {},
"PurchasePriceVarianceAccount": {
"value": "52300"
},
"PurchasePriceVarianceSubaccount": {
"value": "CON000"
},
"PurchaseUOM": {
"value": "EA"
},
"ReasonCodeSubaccount": {
"value": "CON000"
},
"SalesAccount": {
"value": "40000"
},
"SalesSubaccount": {
"value": "CON000"
},
"SalesUOM": {
"value": "EA"
},
"StandardCostRevaluationAccount": {
"value": "52110"
},
"StandardCostRevaluationSubaccount": {
"value": "CON000"
},
"StandardCostVarianceAccount": {
"value": "52100"
},
"StandardCostVarianceSubaccount": {
"value": "CON000"
},
"SubjectToCommission": {
"value": false
},
"TaxCategory": {
"value": "TAXABLE"
},
"ValuationMethod": {
"value": "Average"
},
"VolumeUOM": {},
"WeightUOM": {},
"custom": {},
"files": []
}
If the Attributes are already present on the Stock Item screen, then you can use the Default endpoint and you only need to make a PUT call specifying the Inventory ID and the Attribute ID like so:
PUT : localhost/demo172u10/entity/Default/17.200.001/StockItem
{
"InventoryID": {"value": "AACOMPUT01"},
"Attributes":
[
{
"AttributeID": {"value": "Color"},
"Value": {"value": "Black"}
},
{
"AttributeID": {"value": "Configurable Attributes"},
"Value": {"value": "Test"}
}
]
}
This would update the "Color" and "Configurable Attributes" Attributes of the AACOMPUT01 Stock Item with the value specified.
If the Attribute is not on the Stock Item screen then you would need to use the API to target the Item Class screen to add the Attributes that you want there. As if you go to the Stock Item screen you might notice that you cannot add new attributes directly on that screen and that they are actually coming from the Item Class of the Item itself.
This test was done using the Sales Demo Data with Acumatica Version 17.210.0034
This is a guess, but I think you need to add your attributes to your stock item class. Go to IN201000
This ended up being an issue with my own code that was apparently hiding the attributes from the view so that they wouldn’t update. Once I resolved that, now it's working by just include them in the Attributes collection.
The problem: I have 2 identical in terms of settings and mappings indexes.
The first index contains only 1 document.
The second index contains the same document + 16M of others.
When I'm running the query on the first index it returns the document, but when I do the same query on the second — I receive nothing.
Indexes settings:
{
"tasks_test": {
"settings": {
"index": {
"analysis": {
"analyzer": {
"tag_analyzer": {
"filter": [
"lowercase",
"tag_filter"
],
"tokenizer": "whitespace",
"type": "custom"
}
},
"filter": {
"tag_filter": {
"type": "word_delimiter",
"type_table": "# => ALPHA"
}
}
},
"creation_date": "1444127141035",
"number_of_replicas": "2",
"number_of_shards": "5",
"uuid": "wTe6WVtLRTq0XwmaLb7BLg",
"version": {
"created": "1050199"
}
}
}
}
}
Mappings:
{
"tasks_test": {
"mappings": {
"Task": {
"dynamic": "false",
"properties": {
"format": "dateOptionalTime",
"include_in_all": false,
"type": "date"
},
"is_private": {
"type": "boolean"
},
"last_timestamp": {
"type": "integer"
},
"name": {
"analyzer": "tag_analyzer",
"type": "string"
},
"project_id": {
"include_in_all": false,
"type": "integer"
},
"user_id": {
"include_in_all": false,
"type": "integer"
}
}
}
}
}
The document:
{
"_index": "tasks_test",
"_type": "Task",
"_id": "1",
"_source": {
"is_private": false,
"name": "135548- test with number",
"project_id": 2,
"user_id": 1
}
}
The query:
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
[
{
"match": {
"_all": {
"query": "135548",
"type": "phrase_prefix"
}
}
}
]
]
}
},
"filter": {
"bool": {
"must": [
{
"term": {
"is_private": false
}
},
{
"terms": {
"project_id": [
2
]
}
},
{
"terms": {
"user_id": [
1
]
}
}
]
}
}
}
}
}
Also, some findings:
if I replace _all with name everything works
if I replace match_phrase_prefix with match_phrase works too
ES version: 1.5.1
So, the question is: how to make the query work for the second index without mentioned hacks?