spring data mongo Language annotation - spring-data-mongodb

i'm trying to figure out how to use the #Language annotation from spring-data-rest-mongo project;
I would like to store and retrive mongo document and do query on them; the simple document is as follow:
{
id: "abc",
name: "light",
"description": "wave or particle"
}
I would like to store it and retrive it with different languages;
any hint about it?
some sample using spring-data-rest would be greatly appreciated
thanks a lot

The #Language annotation is used to set the language_override property for a full text index and therefore does not help designing a collection of mulitlingual documents.
For more information please see the MongoDB Text Indexes and the Spring Data MongoDB Full Text Search support.

To perform a search for a certain language I usually follow this approach: Multi-language documents example
The entity
#Document
#CompoundIndex(def = "{'language': 1, 'textProperty': 'text'}")
The repository
#Query("{'language': ?0, $text: {$search: ?1, $language: ?0}}")
Stream<TheDocuemnt> findTheDocument(String language, String criteria, Sort sort);

Related

How to fetch documents that are matching the specified term in a inner object in elasticsearch?

I'm having an elastic search index which has the following document sample in it :
{
"height": 2824,
"details": {
'gomathi':{'name':'gomathi','age':10},
'janu':{'name':'janu','age':20}
}
}
The data are pushed into elasticsearch dynamically from user. My goal is to fetch all documents that are containing name as gomathi.
Expected output:
Return documents having the 'gomathi' key in 'details' JSON object.
How to solve this?
Thanks in advance.
I assume details is a nested field in mapping. You could use inner_hits in a nested query for the requirement explained.
Please take a look at inner_hits and nested documentation.

Append sensor data into document in Couchbase database

We are a group of people writing a bachelor-project about storing sensor data into a noSQL-database, and we have chosen couchbase for this.
We want to store quite a few data in the same document, one document per day, per sensor, and we want to append new sensor data witch comes in every minute.
But unforunatly, we are not able to append new data into existing document without overwriting the existing data.
The structure for the documents is:
DocumentID: Sensor + date, ie: KitchenTemperature20180227
{
"topic": "Kitchen/Temp",
"type": "temperature",
"unit": "DegC"
"20180227130400": [
{
"data": "24"
}
],
..............
"20180227130500": [
{
"data": "25"
}
],
}
We are all new to couchbase and NoSql-databases, but eager to learn and understand how we the best way should implemet this.
We've tried upsert, insert and update commands, but they all overwrite the existing document or won't execute because the document already exists. As you can see, we have some top-level information, like topic, type, unit. The rest should be data coming in every minute and appended to the existing document.
Help on how to proceed would be very appriciated.
Best regards, Kenneth
In this case you can use the subdocument API. This allows you to modify portions of a document based on a "path". This image gives the idea for getting a subdocument.
You can mutate subdocuments as well. Look at the subdocument API documentation for Couchbase. There are also blog posts that go through examples in Java and Go on the Couchbase blog site.

Geodjango GeoJSON Serializer geometry always 'null'

Hello friends of GeoDjango and the GeoJSON serlizer. I was following the official GeoDjango Tutorial:
https://docs.djangoproject.com/en/1.8/ref/contrib/gis/tutorial/
So in the end I have a PostgreSQL + PostGIS database full of countries of, their name, their iso3 code and so on. And especially their geometry in mpoly as MultiPolygon (stored in wkb). I want to retrieve the contries from the database using GeoDjango. I am truggling with that.
I can retrieve the properties of one object one after the other:
from django.http import HttpResponse
from django.shortcuts import render
from django.core.serializers import serialize
from AppName.models import WorldBorder
[...]
WorldBorder.objects.filter(name='Germany')[0].name # "Germany"
WorldBorder.objects.filter(name='Germany')[0].iso3 # "DEU"
WorldBorder.objects.filter(name='Germany')[0].mpoly.geojson # long & correct output
So the data is correctly stored in the database and I can retrieve the objects properties. Now I want to get a full geojson file for the country. Django has created the GeoJSON serializer for that:
https://docs.djangoproject.com/en/1.8/ref/contrib/gis/serializers/
If I use it in the described way:
serialize('geojson',
WorldBorder.objects.filter(name='Germany'),
geometry_field='mpoly',
fields=('name',)
)
I get this output:
u'{"type": "FeatureCollection", "crs":{"type": "name", "properties": {"name": "EPSG:4326"}},
"features": [{"geometry": null,"type": "Feature",
"properties":{"name": "Germany" }}]}'
what is driving me crazy is "geometry": null
So it serializes everything, but not the geometry. Why is that? What am I doing wrong? And especially? How do I get the geometry out of my PostGIS database in GeoJSON format using GeoDjango? Any help is appreciated.
Thank you :)
In case anyone else runs into this issue:
It seems the problem is in Django 1.8, geometry has to be passed in the fields for it be serialized.
More here https://code.djangoproject.com/ticket/26138
If anybody is still interested in the answer. After a Django update I could fix it by using the normal serializer from the django packages.
from django.core.serializers import serialize
and then serialized using the 'geojson' option:
serialize('geojson',
WorldBorder.objects.filter(name='Germany'),
geometry_field='geom',
fields=('id', 'name', 'other_properties_you_want')
and it worked like a charm! Except for the fact that the id did not get serialized.

Solr document Submission

I am new in the solr technology.Can you please tell me how a document can submit to solr using user interface.Is it necessary to create xml of the document first?I expect a simplest way of document indexing..
Please Help.
The default Solr RequestHandler (from 4.0) supports four formats: XML, JSON, CSV and javabin. There's a page under the Admin interface to submit documents to the index (select the core and Documents).
There are examples of each of the formats available in the Solr reference guide. If you're using a client library, the library will usually handle this for you anyways, and use an appropriate format depending on which language it's written in and what built-in libraries are available.
The simplest format for manually adding documents is probably JSON:
[
{
"id": "1",
"title": "Doc 1"
},
{
"id": "2",
"title": "Doc 2"
}
]
You can also use the DataImportHandler to import data locally at the server, such as from an SQL-database. In that case you don't submit the actual rows to the server, but you tell the handler to fetch the rows and create documents for you.

Using CouchDB-lucene how can I index an array of objects (not values)

Hello everyone and thanks in advance for any ideas, suggestions or answers.
First, the environment: I am using CouchDB (currently developing on 1.0.2) and couchdb-lucene 0.7. Obviously, I am using couchdb-lucene ("c-l" hereafter) to provide full-text searching within couchdb.
Second, let me provide everyone with an example couchdb document:
{
"_id": "5580c781345e4c65b0e75a220232acf5",
"_rev": "2-bf2921c3173163a18dc1797d9a0c8364",
"$type": "resource",
"$versionids": [
"5580c781345e4c65b0e75a220232acf5-0",
"5580c781345e4c65b0e75a220232acf5-1"
],
"$usagerights": [
{
"group-administrators": 31
},
{
"group-users": 3
}
],
"$currentversionid": "5580c781345e4c65b0e75a220232acf5-1",
"$tags": [
"Tag1",
"Tag2"
],
"$created": "/Date(1314973405895-0500)/",
"$creator": "administrator",
"$modified": "/Date(1314973405895-0500)/",
"$modifier": "administrator",
"$checkedoutat": "/Date(1314975155766-0500)/",
"$checkedoutto": "administrator",
"$lastcommit": "/Date(1314973405895-0500)/",
"$lastcommitter": "administrator",
"$title": "Test resource"
}
Third, let me explain what I want to do. I am trying to figure out how to index the '$usagerights' property. I am using the word index very loosely because I really do not care about being able to search it, I simply want to 'store' it so that it is returned with the search results. Anyway, the property is an array of json objects. Now, these json objects that compose the array will always have a single json property.
Based on my understanding of couchdb-lucene, I need to reduce this array to a comma separated string. I would expect something like "group-administrators:31,group-users:3" to be a final output.
Thus, my question is essentially: How can I reduce the $usagerights json array above to a comma separated string of key:value pairs within the couchdb design document as used by couchdb-lucene?
A previous question I posted regarding indexing of tagging in a similar situation, provided for reference: How-to index arrays (tags) in CouchDB using couchdb-lucene
Finally, if you need any additional details, please just post a comment and I will provide it.
Maybe I am missing something, but the only difference I see from your previous question, is that you should iterate on the objects. Then the code should be:
function(doc) {
var result = new Document(), usage, right;
for(var i in doc.$usagerights) {
usage = doc.$usagerights[i];
for(right in usage) {
result.add(right + ":" + usage[right]);
}
}
return result;
}
There's no requirement to convert to a comma-separated list of values (I'd be intrigued to know where you picked up that idea).
If you simply want the $usagerights item returned with your results, do this;
ret.add(JSON.stringify(doc.$usagerights),
{"index":"no", "store":"yes", "field":"usagerights"});
Lucene stores strings, not JSON, so you'll need to JSON.parse the string on query.

Resources