can anyone help me to translate below SQL query to ELasticSearch DSL form for document selections?
SELECT * FROM table1 WHERE source_id IN (select source_id FROM table2)
This JOIN semantics does not translate to Elasticsearch. If your index had parent/child mapping - you might be able to achieve what you want to do. Another option is to do a two-pass query.
This blog post gives an idea of how relations are modeled in Elasticsearch - Managing Relations in Elasticsearch
Related
How to rename the query response field name just like mysql's select as query in Elasticsearch?
Note this is on the query not influence the index process which is different from this question
I have created an elasticsearch index against a news table on sqlserver using logstash via the JDBC Driver. This all looks good in Elasticsearch.
Using Index Server, the type of query that gets built for that takes the following form:
SELECT News.*, fulltextsearch.rank FROM News INNER JOIN CONTAINSTABLE(News, ( Headline, BodyText ), 'ISABOUT("car track race" WEIGHT(0.65), car NEAR track NEAR race)') fulltextsearch ON News.NewsID = fulltextsearch.[Key] WHERE DateSubmitted <= '01/11/2017' ORDER BY fulltextsearch.rank DESC
Is there any kind of query that I can do in Elasticsearch to give a similar/same outcome as the above.
No, elasticsearch (version 5.3) do not support JOIN like this. See https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html.
I going to do a query that related to two _index ( conn, http). In sql it can be do like following, may I know how DSL query like in elasticSearch ? Please assist me, I really out of idea.
SELECT * FROM elastic INNER JOIN conn ON conn.uid=http.uid
WHERE elastic.date BETWEEN '2016-08-20 00:00:00' and '2016-08-22 13:41:09'
AND conn.service='http' ;
elasticsearch doesn't have support for joins like SQL.
They discuss the handling of relationships in the definitive guide: https://www.elastic.co/guide/en/elasticsearch/guide/current/relations.html
SELECT u.Address,c.locality,jaccard_similarity(u.Address, c.locality) as score
FROM users u
left join communites c on jaccard_similarity(u.Address, c.locality) >=0.65
How do I achieve the same functionality in Elasticsearch?
There is no way to do that natively in elasticsearch.
You'll have to either use nested objects or do application joins ( doing 2 queries in your application).
The documentation will explain the strategies : https://www.elastic.co/guide/en/elasticsearch/guide/current/relations.html
Can you nest queries logically in ElasticSearch, so the output of one query is the input to another query.
Another, way to ask is how can I chain or pipe queries together?
This should be analogous to the IN operator or subqueries in SQL
i.e.:-
select au_lname, au_fname, title from
(select au_lname, au_fname, au_id from pubs.dbo.authors
where state = 'CA')
or
SELECT Name
FROM AdventureWorks2008R2.Production.Product
WHERE ListPrice =
(SELECT ListPrice
FROM AdventureWorks2008R2.Production.Product
WHERE Name = 'Chainring Bolts' );
Elasticsearch doesn't support subqueries; you would need to perform your first query, then construct a second query using the results of the first query as an input.
this is not supported in elastic-search you must normalize your data and have all field you need in one setting
That is totally correct, you must programm a subquery in your favorite programming language. An example can be found here:
https://sebastianviereck.de/elasticsearch-subquery-scoring-optimization/