doc frequency for multiple fields in single query in elasticsearch - search

how to get doc frequency of multiple fields in single query. If we query with name and address. it should return docfrequency of name index and lat_long index based on the inquiry.

As far as I know, you can't do it in a single query. Why not multiple queries, but not retrieving the full document when you don't need it (so it's faster).

Related

Mongodb, should a number fields be indexed?

I'm trying to get a proper understanding of using mongodb to optimise queries. In this case it's for fields that would hold an integer. So say i have a collection
with two fields value and cid where value will store data of type string and cid will store data of type number.
I intend to write queries that will search for records by matching the fields value and cid. Also the expectation is that the saved records for this collection would get very large and hence queries could benefit from mongodb indexes. It makes sense to me to index the value field which holds string. But I wonder if the cid field requires indexing, or its okay as is, given that it will be holding integers.
I'm asking because I was going through a code base with this exact scenario described and i can't figure out why the number field was not indexed. Hoping my question makes any sense.
Regardless of datatypes, generally speaking all queries should use an index. If you use a sort predicate you can assist the database by having a compound index on both the equality portion of the query (the filter predicate) as well as the sorting portion (the sort predicate). MongoDB recommends following the index strategy referred to as the E.S.R. rule - see Performance Best Practices for E.S.R. rule.

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.

The implication of #search.score in Azure Search Service

I understood the reason for having search profile and boosting results based on some fields e.g. distance, rating, etc. To me, that's most likely applicable to structured documents like json files. The scenario that I cannot make sense of it is when indexer gets search service index let's say a MS Word or PDF document in azure blob. We have two entries of "id" and "content" which I don't know how the search score would apply to it.
For e.g. there are two documents with different contents. I searched for a keyword and the same keyword found in two documents resulted into getting two different scores for two MS Word documents. My challenge is why this score should be different while both documents contain the same keyword?
The score is determined by many factors, for example, the count of terms in each document, and the number of searchable fields in which query terms were found. In your example, the documents have different lengths, so naturally they'll have different scores. HTH.

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})

How to retrieve search results from two fields in lucene index, giving one query?

Suppose I search for a query in Field A, and I want to retrive the corresponding fields B and C from my index, how should I go about it? I am using Lucene 3.6.0.
The results of your query will be returned as a set of documents, not fields. Once you've got a document, you can load whichever field contents you're interested in.
One thing that's probably worth watching out for is to ensure that your fields have been "stored".
Good luck,

Resources