GlobalSecondary index in DynamoDB - java

I have to create a Global Secondary Index in Dynamo Db. My Primary table structure is below -
{
"primaryId" : "1234" //HashKey
"dummy1" : "kkd",
"dummy2" : "ddd",
"secondObj": [{
"secondObjId" : "1234",
"name" : "1234",
},
{
"secondObjId" : "12345",
"name" : "12345",
}]
}
Now i have to create GlobalSecondary Index based on "secondObjId" as a hashkey. is it possible to create?
I have created it using AWS console but its showing item count 0 and if i am creating GlobalSecondaryIndex using "dumy1" then its showing proper item count.
So my query is that is it possible to create a GlobalSecondayIndex based on a attribute from DynamoDBDocument?

Indexes can be built only on top-level JSON attributes. In addition, range keys must be scalar values in DynamoDB (one of String, Number, Binary, or Boolean).

Related

Update/add a single value to an array in MongoDB - but not as list?

I want to simply add one value to a tuple from MongoDB.
The key is query, and the variable position should be added as consumer-Variable in the tuple with the following code:
MongoCollection<Document> collection = ...
Bson filter = Filters.eq("query", queryName);
Bson update = Updates.addToSet("consumer", position);
collection.findOneAndUpdate(filter, update);
However, when I look into my database, it looks like a list "consumer" : [ NumberLong(88760) ] has been inserted and not a single value, as shown in the producer field:
{ "_id" : ObjectId(...), "query" : "1000", "consumer" : [ NumberLong(88760) ], "producer" : NumberLong(88760) }
I also tried Update.push() with the same result.
How can I add just a single value, without having it as list?
For example, if you need to update only 1 object from the list inside, you can do it in the format as:
.update_one({"_id": ObjectId(_id)}, {"$set": {"i.5": list[2]}})
where "i.5" - 5 index of the list i.

How to remove an item in an array in Firebase database?

I am sending an object to Firebase which has an ArrayList of users. I need to delete a user from this array. How can I do to know the position of the user in this array and delete it?
"room" : {
"-LswnaENRCSpJdB8-ZBg" : {
"description" : "",
"members" : [ {
"id" : "jh4Ch9rBgQPwBTfv...",
"name" : "John",
}, {
"id" : "5P6DzPIEuiSKU5UY...",
"name" : "Jack",
}, {
"id" : "nKTlIyaDc3O3gxNp...",
"name" : "Mary",
} ],
"name" : "MyRoom"
},
Thanks in advance!
How can I do to know the position of the user in this array and delete it?
There is currently no way you can create a query that can help you find a specific user that exists at a particular index in your members array.
To actually remove a particular user you'll need to load the entire members array, remove the user that you want client-side, and then write the entire array back.

How to Compare and fetch the Json records having same Name in descending order

I have a json with n number of objects I have to fetch "id" attribute from last two objects. Also I have to first compare Id attribute as per the latest added objects to json. Say Id 16941 is to be fetched first and then id 16940 has to be fetched second.
[
"id" : 16940,
"version" : 0,
"direction" : "B",
}, {
"id" : 16941,
"version" : 0,
"direction" : "S",
} ]

How to index documents containing nested properties with Lucene?

I'll try to reduce my case to the necessary: I'm building a Webapp (with Spring) with a search interface that lets you search a corpus of annotated/tagged texts. In my DB (MongoDB) one document represents one page of a book collection (totaling ~8000 pages).
Here is an example of the Document structure in JSON (I removed a lot of meta data for brevity. Also, and this is important, the "tokens"-array contains up to 700 objects in most cases.):
{
"_id" : ObjectId("5622c29eef86d3c2f23fd62c"),
"scanId" : "592ea208b6d108ee5ae63f79",
"volume" : "Volume I",
"chapters" : [
"Some Chapter Name"
],
"languages" : [
"English",
"German"
],
"tokens" : [
{
"form" : "The",
"index" : 0,
"tags" : [
"ART"
]
},
{
"form" : "house",
"index" : 1,
"tags" : [
"NN",
"NN_P"
]
},
{
"form" : "is",
"index" : 2,
"tags" : [
"V",
"CONJ_C"
]
}
]
}
So you see i don't have a plain text, here. I now want to build an index with Lucene to quickly search this DB. The problem is that i want to be able to search certain words, their tags AND the context around it. Like "give me all documents containing the word 'House' tagged as 'NN' followed by a word tagged with 'V'.". I couldn't find a way to index these sub-structures with native Lucene functionality.
What i tried to do to at least be able to search for words and their tags is the following: In my Lucene index, a document doesn't represent a whole page, but only a word/token with it's tags. So one index document looks like this (expressed in JSON syntax for readability):
{
"token" : "house",
"tag" : "NN",
"tag" : "NN_P",
"index" : 1,
"pageId" : "5622c29eef86d3c2f23fd62c"
}
... Yes, Lucene allows me to use one field multiple times. So now i can search for a word and it's tags and get a reference to the page object in my DB via it's ID. But this is pretty ugly for two reasons: I now have two completely different document representations (DB and Lucene index) and to process a complex query like the one i mentioned above i'd have to query for the word and it's tag and then further check the context of the hits in the retrieved documents manually.
So my question is: Is there a way to index documents in Lucene containing fields/properties whose values are nested objects that in turn have certain properties?
Is there a way to index documents in Lucene containing fields/properties whose values are nested objects that in turn have certain properties?
Elasticsearch certainly lets you do this. I think it's possible to do all of it in pure lucene, but may be some effort.
Basically, you need to use the 'nested' query: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
PUT /my_index
{
"mappings": {
"type1" : {
"properties" : {
"tokens" : {
"type" : "nested"
}
}
}
}
}
This tells ES to index the contents of this field as a list of separate documents, allowing you to query them individually using the 'nested' query:
GET my_index/_search
{
"query": {
"nested": {
"path": "tokens",
"query": {
"bool": {
"must": [
{ "match": { "tokens.form": "house" }},
{ "match": { "tokens.tags": "NN" }}
]
}
}
}
}
}

Java - MongoDB - Map Json object as Java Array

I've got an XML configuration mapped to a JSON document which has an array of elements, but when there is only one element, the document looks like this:
{
"name" : "test2"
"products" : {
"id" : "prod3"
"value" : "prod_value3"
}
}
{
"name" : "test1"
"products" : [
{
"id" : "prod1"
"value" : "prod_value1"
},
{
"id" : "prod2"
"value" : "prod_value2"
}
]
}
Instead of an array of elements, there is only one element "products"
The JSON is inserted into the MongoDB database and I'm trying to map the "products" as an ArrayList but in the first example, the array returns empty.
My question is: Is there any way to automatically map this case with Java? Maybe a customMapper?
This case in Java is known as overloading methods. Object of some class and array are different types. You can't use one typecast to another etc., but you can use different type of parameter in the method accepting the value.

Categories