Elasticsearch query against multiple types - elasticsearch

I have two types stored in ES:
Photos (fields: photo-id, description, createDateAsLong)
VisitHistory (username, photo-id - with 30days TTL)
Is it possible to query ES for records of type Photos which photo-id doesn't exists in VisitHistory (for some username value). I mean a query which is equivalent of sql query like this:
SELECT * FROM Photos WHERE photo-id NOT IN (SELECT photo-id FROM VisitHistory WHERE username = 'somefoousername');

If you make Photos a parent document and VisitHistory a child document of Photos, you should be able to use a combination of not and has_child filters to build such request.

Related

Is it possible to evaluate SQL given as text? (Oracle APEX 21.1)

I have created a classic report region (REGION: REPORT_FILTER_SHOP_TYPE).
That has a SQL below this.
SELECT
ID, SHOP_NAME, SHOP_TYPE, OPEN_YEAR, CITY
FROM SHOP_LIST;
I want to apply a filter to this table. The filter criteria will be selected from the list item. And this page have some lists.
For example, if there is no filter, the SQL right above one. But if the "SHOP_TYPE" and "OPEN_YEAR" are selected, execute the SQL below.
SELECT * FROM (
SELECT
ID, SHOP_NAME, SHOP_TYPE, OPEN_YEAR, CITY
FROM SHOP_LIST
) S
WHERE S.SHOP_TYPE = 'BOOKSTORE' AND S.OPEN_YEAR <2010;
I can now create the compose SQL text from selected list items.
What do I need to set to display this result in REPORT_FILTER_SHOP_TYPE?
Well, most probably not like that; why using parameters on a page if you hardcode some values into report's query? Use parameters!
Something like this:
SELECT id,
shop_name,
shop_type,
open_year
FROM shop_list
WHERE ( shop_type = :P1_SHOP_TYPE
OR :P1_SHOP_TYPE IS NULL)
AND ( open_year < :P1_OPEN_YEAR
OR :P1_OPEN_YEAR IS NULL);

Query to find DISTINCT between array of objects in Cosmos DB [ SQL API ]

I am using Azure Cosmos DB with SQL API and we need to find the DISTINCT values between array of objects in the same document.
I have structured the collection in the following ways
I have 2 main attribute RID and RNAME. In the first collection, I have only one document which contains all the RID and RNAME mapping in the array of objects.
"Details":[
{
"RID":"1",
"RNAME:"Car"
},
{
"RID":"1",
"RNAME:"Car"
}]
In second collection, I have multiple documents for each RID and RNAME mapping.
{
"RID":"1",
"RNAME:"Car"
}
I am using Stored procedure and I need to know which one is a good way to get DISTINCT of RNAME using stored procedure.
Using first collection, I am not sure how to query to find DISTINCT RNAME between objects in the array.
Using second collection. when I use the SQL editor, the distinct Query works but not sure how to put it in Stored procedure.
DISTINCT Values of RNAME
1.multiple documents
use sql:
select distinct c.RNAME from c
2.single document
use sql:
SELECT distinct d.RNAME FROM c
join d in c.Details

How to query distinct documents that contain Unordered List properties in FileNet P8?

I am trying to send a dynamically built query to FileNet 5.2 using the .Net API. The Document Class that I am trying to query has three properties in the select list that have a cardinality of Unordered List and type String. When I send over the query with the DISTINCT keyword, FileNet returns this error:
Can't select property with "distinct": RouteNumber.
Here is an example SQL statement that is getting passed to FileNet:
SELECT DISTINCT
td.DrawingNumber,
td.ProjectTitle,
td.WorkArea,
td.RouteNumber,
td.City,
td.County,
td.DrawingNumberAssignedYear,
td.Comment,
td.MajorVersionNumber,
td.IsCurrentVersion
FROM TrafficDocument AS td WITH EXCLUDESUBCLASSES
LEFT OUTER JOIN RoadwaySegment AS rwy WITH EXCLUDESUBCLASSES ON td.ID = rwy.ParentObjectID
WHERE td.IsCurrentVersion = True
AND '104' IN RouteNumber
ORDER BY td.DrawingNumber, td.TrafficPlanDiscipline
OPTIONS (TIMELIMIT 180)
I need the DISTINCT keyword because the joining document class, RoadwaySegment, is causing duplicates but it is needed in the query because their values can be filtered against as well.
So how can I achieve my goal of querying FileNet and retrieving unique results?
Is RouteNumber an orderable property? Only orderable ones are allowed for queries with DISTINCT.
DISTINCT restrictions:
A DISTINCT query can be performed only when all
of the SELECTed properties are orderable. For example, if property P1
is not orderable (Binary type, or String type with UsesLongColumn),
the following query produces an error message:
SELECT DISTINCT P1 From Object1

Oracle 11g Text: Composite Domain Index - FILTER BY on columns from different tables

I am using Oracle 11g Text,
AuthorTable : (a table for Author details)
AuthorId, AuthorName, AuthorDOB
ArticleTable : (a table for Article content) ArticleId, WrittenDate, PublishDate, ARTICLE_TXT (CLOB)
LocationTable : (a table for Location) LocationId, LocationState, LocationCity
ArticleAuthorAssocTable: (a table for Article-Author Association) AuthorId, ArticleId
LocAuthorAssocTable: (a table for Author-Location Association) AuthorId, LocationId, LocationStartDate, LocationEndDate
My query need to search for any input search term on ARTICLE_TXT along with any other query on PublishDate / WrittenDate / AuthorDOB / LocationCity / LocationStartDate range.
As I have to do a mixed-query, I started creating Composite Domain Index CDI on ArticleTable.
CREATE INDEX ARTICLE_TXT_CDI_IDX ON ArticleTable(ARTICLE_TXT)
INDEXTYPE IS ctxsys.CONTEXT
FILTER BY WrittenDate, PublishDate
and the query as
SELECT
/*+ domain_index_sort domain_index_filter(ARTICLE_TXT_CDI_IDX) */ article.ARTICLE_TXT,
author.AuthorName , article.WrittenDate, article.PublishDate, LocationTable.LocationCity ,location.LocationStartDate, location.LocationEndDate
FROM
ArticleTable article
INNER JOIN
ArticleAuthorAssocTable articleAuthorAssoc ON article.articleId = articleAuthorAssoc .articleId
INNER JOIN
AuthorTable author ON author.authorId= articleAuthorAssoc.authorId
INNER JOIN
LocAuthorAssocTable locAuthorAssoc req ON author.authorId = locAuthorAssoc.authorId
INNER JOIN
LocationTable location ON location .authorId = locAuthorAssoc.authorId
WHERE
CONTAINS(article.ARTICLE_TXT, 'Something') >0
AND author.AuthorDOB BETWEEN TO_DATE('01/01/2001','MM/DD/YYYY')
AND TO_DATE('12/31/2012','MM/DD/YYYY')
AND location.LocationId IN (1,2)
Now my questions are:
Is it possible to create Composite Domain Index with FILTER BY on
columns from different tables ?
Is there any other way to improve the above query ?
From my research, some options are using materialized view, function-based index, USER_DATASTORE
But unfortunately still not sure how to use them... Please help me with your knowledge.
Thanks
I think the best solution to this problem is to add a XML column to the ArticleTable where you combine all the required info of the article.
Then you need to add triggers to the involved tables to recreate this xml when data changes are happening.
This way you could index this xml column and search for very specific information, using section groups (eg like 'PATH_SECTION_GROUP')

How can I use Linq to join between objects and entities?

I have a collection of IDs in memory, and I would like to fetch only rows from a DB matching those IDs.
In SQL, I could either write a query like SELECT * FROM mytable WHERE id IN (1,3,5,10) or do a join between tables.
My problem is that EF can't build a query where I join my EF-data with my local array or list.
(I'm using EF4.1, but I'm guessing the problem/solution would be similar in older versions, as well as with Linq-to-SQL.)
You can use Contains() with your ID collection myIDs to generate the equivalent WHERE id IN .. query:
var results = context.mytable.Where(x => myIds.Contains(x.Id));

Resources