Java - (JSON) What is this called? - java

Guide I'm working with: http://crunchify.com/how-to-write-json-object-to-file-in-java/
I've currently created an application which downloads a big JSON file and parses the data which list items into it, but unfortunately all items are named as it's ID so basically it means that I have to fetch all of the item ID's from separate files, because their JSON doesn't support querying a many items once i.e "item=1983,1093,984,2847" so I have do it for EVERY item individually.
That means I have to make many query connections to remote service in order to find names of up to 35,000 items which isn't very good choice since my query limit will reach to maximum in a seconds.
I want to create a custom JSON file that the item ids and names are fetched into it so it won't use anyone's bandwidth in order to gain item name.
So I'm thinking about 2D array, it's like [int][int] so what is this called for and how do I make my Java JSON (json-simple-1.1.1) understand that the item id will be the (object?) and rest info that relates to that id will be (key?)
{
"1094" // Item ID
{
"name": "item name",
"info": "item info"
}
}
In PHP there was something similar like this:
foreach($whatever as $something => $key) {
}
Item ID must be the identifier that I can parse rest of the details from it.
Edit: So "item id" should be JSONArray which is placed to object so I can add "keys" to it? I'm not sure about the terms.

Related

How to search in firebase database

I'm trying to filter the data from my database using this code:
fdb.orderByChild("title").startAt(searchquery).endAt(searchquery+"\uf8ff").addValueEventListener(valuelistener2);
My database is like this:
"g12" : {
"Books" : {
"-Mi_He4vHXOuKHNL7yeU" : {
"title" : "Technical Sciences P1"
},
"-Mi_He50tUPTN9XDiVow" : {
"title" : "Life Sciences"
},
"-Mi_He51dhQfl3RAjysQ" : {
"title" : "Technical Sciences P2"
}}
While the code works, it only returns the first value that matches the query and doesn't fetch the rest of the data even though it matches.
If I put a "T" as my search query, I just get the first title "Technical Sciences P1 " and don't get the other one with P2
(Sorry for the vague and common question title, it's just I've been looking for a solution for so long)
While the codes works, it only returns the first value that matches the query
That's the expected behavior since Firebase Realtime Database does not support native indexing or search for text fields in database properties.
When you are using the following query:
fdb.orderByChild("title").startAt(searchquery).endAt(searchquery+"\uf8ff")
It means that you are trying to get all elements that start with searchquery. For example, if you have a title called "Don Quixote" and you search for "Don", your query will return the correct results. However, searching for "Quix" will yield no results.
You might consider downloading the entire node to search for fields client-side but this solution isn't practical at all. To enable full-text search of your Firebase Realtime Database data, I recommend you to use a third-party search service like Algolia or Elasticsearch.
If you consider at some point in time to try using Cloud Firestore, please see the following example:
Is it possible to use Algolia query in FirestoreRecyclerOptions?
To see how it works with Cloud Firestore but in the same way, you can use it with Firebase Realtime Database.

Elasticsearch update document without creating new index

I have many existing indices partition by date. Eg: index_190901, index_190902,...
And I have an API which takes index_name and doc_id as inputs. User want to update some documents in index by input fields, index_name, doc_id.
I'm trying to update document using the following code:
updateRequest.index("invalid_daily_index")
.type("type")
.id("id")
.doc(jsonMap)
It works fine if user input existing index but if user input non-existing index, new index with no document will be created.
I know that I can setup auto_create_index but I still want to create index automatically when I insert new documents.
Check if index is existed with client.indices.exists(request, RequestOptions.DEFAULT) is quite expensive. I don't want to check it every request
How to make Elasticsearch to not create new index when I use updateRequest.
You can block the option to automaticaly create non existing indices by putting false to the action.auto_create_index setting of the cluster
PUT _cluster/settings
{
"persistent" : { "action.auto_create_indexā€¯ : "false" }
}
For details take a look at the reference

How to evolve schema in Janusgraph?

I uploaded movie and user data to janusgraph and initially I made index on movieId but, later I realised I need to index movie title as well. I need to do query based on movie title and without indexing movie id, it's giving me warning "Query requires iterating over all vertices". So, I added the code:
JanusGraphManagement mgmt = graph.openManagement();
PropertyKey title = mgmt.getPropertyKey("title");
JanusGraphManagement.IndexBuilder movieNameIndexBuilder = mgmt.buildIndex("title", Vertex.class)
.addKey(title);
movieNameIndexBuilder.unique();
JanusGraphIndex movieTitleIndex = movieNameIndexBuilder.buildCompositeIndex();
mgmt.setConsistency(movieTitleIndex, ConsistencyModifier.LOCK);
mgmt.commit();
Still I'm getting the same warning "Query requires iterating over all vertices" when I'm querying on movie title.
Thank you
Got the solution from Janusgraph gitter channel:
The index isn't available immediately if the the indexed property key was created in a previous management transaction as JanusGraph might need to reindex existing data now. That is a process you have to trigger manually. You can read more about this in the chapter Index Management of the docs.
That is why it's recommended to create all indices in the same transaction where you create the property keys if possible

Rethinkdb : i need a simple query in java to update the list of items

This is my rethink document I need a simple query in java to update the menuItemIds list.
{
"id": "1a89a4b6-36a3-4378-8ddb-26d0d90f3055" ,
"menuItemIds": [
"178de705-59d7-4c5d-8a25-f7e0a226e510" ,
"sfefe-edwef-wefwefwe-wef"
],
"vendorId": "e2c1e97d-3996-40c2-9c14-86f824203812"
}
Updating a record in rethink works like this: fetch the row you want through get(id) and call update(). Pass the new list through a hashmap.
r.table('tableName').get("1a89a4b6-36a3-4378-8ddb-26d0d90f3055")
.update(r.hashMap("menuItemIds", newMenuList)).run(conn)
You might want to check out the documentation.

MongoDB full text search index: error: too many text index for, why?

I have one problem, I have collection and I want to set text search index to 2 fields(description and title). But when I add second index I get following error and text search stopped working.
{ "serverUsed" : "localhost/127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "too many text index for: testdb.users"}
when I delete one index search start work again. what is the problem? One collections support full text search index only for one field????
I am using the current version of mongodb under windows and I am using mongodb java driver API.
Thanks
MongoDB only allows one text-index per collection.
But you can use a text-index which spans multiple fields:
db.collection.ensureIndex( {
description: "text",
title: "text"
} );
That way you will get results when the phrase you are searching for is found in either. When this is not what you want, like when you have two search-queries which each return results from one of the fields but not the other, you have two options.
use a multi-field text index, but discard the results which come from the wrong field on the application layer.
extract one of the two fields to a different collection. The documents in that collection could either contain full copies, redacted copies or just the field you index and the _id of the original document.
To create a text based index on a key, use command db.collectionName.ensureIndex({'textColumnName': 'text'}). After this index is applied, use the search commands to search for a word i.e. db.collectionName.find({$text: {$search:'your text here'}}). There is a text score based on which the results are ranked, to see it project it in the score key like this : db.collectionName.find({$text: {$search:'your text here'}}, {score: {$meta: 'textScore'}}).sort({score: {$meta: 'textScore'}}).
If we create a text index on the title field of the movies collection, and then perform the text search db.movies.find( { $text : { $search : "Big Lebowski" } } ). The following documents will be returned, assuming they are in the movies collection:
{ "title" : "The Big Lebowski" , star: "Jeff Bridges" }
{ "title" : "Big" , star : "Tom Hanks" }
{ "title" : "Big Fish" , star: "Ewan McGregor" }
This is because, there will be a ***logical OR***ing on Big & Lebowski.

Categories

Resources