Elasticsearch while updating one index it should also update other index values - search

I need to update a lat_long field in 'ADDRESS' index when updating the values in the 'USER' index. Is there a way to trigger event in elasticsearch internally from the server side to update the Address index while updating the USERindex ?

Related

Filter, Sort and Paginate in mongoose returns duplicate value

I have a product document in mongodb. I am retrieving data with paging using skip and limit after filtering and sorting, like this using mongoose -
Product.find({gender:'male'})
.sort(price: 1)
.skip(page * 25).limit(25);
When page value is 0 it returns the result as expected, but when the page value changes to 1 it returns some results that were already retrieved when page value was 0. I am passing all these parameters through query in nodjs express. How can i retrieve unique value only with sorting and filtering while using pagination with mongoose ?
As mentioned here:
MongoDB does not store documents in a collection in a particular order. When sorting on a field which contains duplicate values, documents containing those values may be returned in any order.
If consistent sort order is desired, include at least one field in
your sort that contains unique values. The easiest way to guarantee
this is to include the _id field in your sort query.
So you can solve the problem by:
Product.find({gender:'male'})
.sort({price: 1, _id: 1})
.skip(page * 25).limit(25);

MongoDB: Understanding index types and index properties

From the MongoDB documentation they have stated six index types :
Single Field Index
Compound Index
Multikey index
Geospacial index
Text index
Hashed index
The documentation has also stated four index properties.
Unique Indexes
Partial indexes
Sparse Indexes
TTL Indexes
My questions are:
Can any index type have any index property?
Can an index type have more than one index property?
According to the docs: MongoDB creates a unique index on the _id field during the creation of
a collection. Does this mean when I search by Id MongoDB does not do a collection scan but instead uses the id index to execute the query efficiently? Or is the default id index just for uniqueness only? Does a unique index property always support faster queries?
I am using MongoDB via mongoose. When defining a schema in node.js does the field unique: true imply indexing of that will result to efficient search as opposed to a collection scan?
Can materialized views be indexed in MongoDB? If so how?
In the MongoDB documentation it states that MongoDB provides a number of different index types to support specific types of data and queries. Gut there is no explanation of what index properties are. How would you define index properties?
Can any index type have any index property?
Can an index type have more than one index property?
You can test yourself and find out.
Does this mean when I search by Id MongoDB does not do a collection scan but instead uses the id index to execute the query efficiently?
Yes.
Does a unique index property always support faster queries?
Uniqueness refers to a restriction on data which can be placed in the field which is indexed. Both unique and non-unique indexes allow fast retrieval of data queried by indexed fields.
Can materialized views be indexed in MongoDB?
If you are talking about https://docs.mongodb.com/manual/core/materialized-views/, "materialized views" in MongoDB are orthogonal to indexes. You can add indexes on what this page refers to as "output collection" (the argument to $merge) if you wish to query the "materialized view" efficiently.
MongoDB provides a number of different index types to support specific types of data and queries.
Geospatial index supports geo queries. Text index supports text search. Other indexes are general-purpose.

Azure Search indexer does not pick up update to null

In the cosmos db I have array element "X" and it's mapped to in the index field "X" Collection(Edm.string). If I update X to null then changes does not reflect in the Azure search. Indexer picks up the timestamp change but actual value does not show up in the index. (but if you assign any value, it's show up in the index). Basically when you make your element null, index does not show "null" instead it shows old value.
Any idea how i can fix this?
Set the field to an empty array.
Setting a fields value to null removes it from the index (in contrast to setting it to an empty string or 0).
Collections are, well, collections of values. You can remove values from the collection, but not the collection itself.

Duplicate Error on adding data in mongoDB

I am trying to insert data in mongoDB document but I am getting duplicate error in it.
While defining the schema, I have given the value of "role" as default:"customer".
But on adding data with different number, i am getting this error.
Following is the schema defined:
Where is the error?
Check if the collection have unique index on the column.
db.customers.getIndexes()
here you will get unique index on userName. drop it
It will return all the indexes. If it have unique: true then drop it and then insert records.
OR just use
db.customers.dropIndex('username_1')
It's not the error because of mobilenumber. it's because of username. you are trying to insert multiple username with null value which is violating unique rule.

Insert docs in sorted order on mongodb

In mongodb, I want to insert the data in sorted order based on some field.
The way I am doing, before insertion compare the data with data which is in collection and then insert it on that particular position. Is the insertion at particular position is possible in mongodb using node.js
You can't insert a doc at a specific spot in the collection. Even if you could, it wouldn't matter because you can't rely on the natural order of MongoDB documents staying consistent as they can move over time as the docs in a collection are updated.
Instead, create an index on the field(s) you need your docs sorted on and then include a sort clause in your queries to efficiently retrieve the docs in that order.
Example in the shell:
// Create the index (do this once)
db.test.ensureIndex({someField: 1})
// Sorted query
db.test.find().sort({someField: 1})

Resources