Elasticsearch case insensitive nested query string - elasticsearch

I haven't defined any analyzers and assume it's using the standard analyzer
ES version : 5.6
Lucene_version : 6.6.1
Normal query string results in case-insensitive search but if the query string is put inside nested query it results in case sensitive search
Non-nested query string
GET articles/_search
{
query : {
bool : {
must : [ {
query_string : {
query : "*ellow*
}}]}
}
Nested query string doesn't return case insensitive matches
GET articles/_search { query : {
bool : {
must : [ {
nested : {
path : "comments",
query : {
query_string : {
query : "*ellow*"
}}}} ]} }
Any help is greatly appreciated.
Thanks

Related

Elasticsearch : get compliment of output

I want to get set of result which is outside the provided filters.
Example :
Query : document_id and filter
{
Document_id : 1,2,3,4,5,6,7
},
{
Query Result : 1,2,3,4,5,6
}
Output : 7
I can perform the above manipulation in java code as well but I want to get this result from Query. Any help would be appreciated.
You should put your filter in a must_not clause inside a bool query, like this:
POST _search
{
"query": {
"bool" : {
"must_not" : [
<YOUR FILTER QUERIES HERE>
]
}
}
}

How do I write an OR query in Kibana (ElasticSearch)?

Using ElasicSearch's JSON Query DSL through Kibana, how do I retrieve all documents which have:
messageTemplate equals My message
or
level equals Error
You have to use a Bool query for that :
... If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query
POST <your_index>/_search
{
"query": {
"bool": {
"should": [
{ "match_phrase" : { "messageTemplate" : "My message" } },
{ "term" : { "level" : "Error" } }
]
}
}
}
Alternatively, you could type in the Kibana search bar:
messageTemplate:"My message" || level:"Error"
or
messageTemplate:"My message" OR level:"Error"

How to achieve the following sql query in elasticsearch?

Want to know the equivalent elasticsearch query for the below sql query?
SELECT * FROM table1 where val1 in (SELECT val1 FROM table1 WHERE val2 = "123");
How to achieve this in an effiecient way?
One way is to fetch all val1 in 1st Elasticsearch query and with the val1 values fetch all values in the 2nd Elasticsearch query. Is there any other way with which we can get the results in a single Elasticsearch query instead of two Elasticsearch query
You could have your query as such assuming that your heading towards a HTTP POST request.
Request:
http://localhost:9200/yourindex/_search
Request Body:
{
"query": {
"query_string": {
"query": "val1:(val2:\"123\")"
}
}
}
Instead of using the IN keyword, you could go with the : symbol in ES OR you could still use the Terms Query . This SO & this thread could be helpful.
EDIT
Using the terms query:
{
"query" : {
"bool" : {
"filter" : {
"terms" : {
"val1" : [ "val2" : ["123"]]
}
}
}
}
}

Elasticsearch document aliases

I have multiple mappings which come from the same datasource but have small differences, like the example below.
{
"type_A" : {
"properties" : {
"name" : {
"type" : "string"
}
"meta_A" : {
"type" : "string"
}
}
}
}
{
"type_B" : {
"properties" : {
"name" : {
"type" : "string"
}
"meta_B" : {
"type" : "string"
}
}
}
}
What I want to be able to is:
Directly query specific fields (like meta_A)
Directly query all documents from the datsource
Query all documents from a specific mapping
What I was looking into is the type filter, so preferably I could write a query like this:
{
"query": {
"filtered" : {
"filter" : {
"type" : { "value" : "unified_type" }
}
}
// other query clauses
}
}
So instead of typing "type_A","type_B" in an or clause in the type filter I would like to have this "unified_type", but without giving up the possibility to directly query "type_A".
How could I achive this?
I don't think that it's possible. However, you could use copy_to functionality, so you would have your fields as they are now and their values copied into unified name.
The copy_to parameter allows you to create custom _all fields. In
other words, the values of multiple fields can be copied into a group
field, which can then be queried as a single field. For instance, the
first_name and last_name fields can be copied to the full_name field
as follows:
So you'd be copying both "meta_A" and "meta_B" into some "unified_meta" field and query this one.

Nested filter returns wrong result when Object name is not given to search

Using elastic search, I am trying to get data for nested object
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
NestedQueryBuilder nestedBuilder = QueryBuilders.nestedQuery("Attributes", boolBuilder);
boolBuilder.must(QueryBuilders.termQuery("Attributes.attributeId", "1001"));
Result comes if the query is like this,
{
"nested" : {
"query" : {
"bool" : {
"must" : [ {
"term" : {
"Attributes.attributeId" : "1001"
}
]
}
},
"path" : "Attributes"
}'
Result not coming if the query is like this,
{
"nested" : {
"query" : {
"bool" : {
"must" : [ {
"term" : {
"attributeId" : "1001"
}
]
}
},
"path" : "Attributes"
}
Can somebody help me.Here i have to get result without using "Attributes.attributeId".ie. using "attributeId" alone data have to come.
This is expected as per the nested query documentation
The query path points to the nested object path, and the query (or
filter) includes the query that will run on the nested docs matching
the direct path, and joining with the root parent docs. Note that any
fields referenced inside the query must use the complete path (fully
qualified).

Resources