How to match non existant tags

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd
and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value
of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd
and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher score.

See Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi azitabh@gmail.com a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d '{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

Thanks David.
But I missed a condition in my earlier post.
I also want documents in return which doesn't have any of the tag a & b.
Which simply means that I want to match a & b only if those are there.
This I don't think can be modeled in the bool query you have suggested.

-Azitabh

On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:

You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher
score.

See Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi <azi...@gmail.com <javascript:>> a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd
and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value
of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd
and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

--

"Should" means that the query is not mandatory.
If you have a 3rd condition (mandatory or a MatchAll), you can create a bool query with :
Must -> Your Mandatory Query or MatchAll
Should -> TermQuery on "a"
Should -> TermQuery on "b"

It should work. Or I did not fully understand your use case.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 08:16, azi azitabh@gmail.com a écrit :

Thanks David.
But I missed a condition in my earlier post.
I also want documents in return which doesn't have any of the tag a & b.
Which simply means that I want to match a & b only if those are there.
This I don't think can be modeled in the bool query you have suggested.

-Azitabh

On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:
You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher score.

See Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi azi...@gmail.com a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d '{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

--

Should means at least one(or otherwise mentioned) of the conditions
specified should match.
So If I say:
should a=abcd
should b=wzyz

This will give me all documents which match the condition (the value of 'a'
is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and tag
'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is wxyz).

But what I want in return is all documents which match the condition (the
value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is
abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of
'b' is wxyz) or (tag 'a' doesn't exist and tag 'b' doesn't exist).

Correct me if I am wrong.

-Azitabh

On Tuesday, 6 November 2012 12:55:36 UTC+5:30, David Pilato wrote:

"Should" means that the query is not mandatory.
If you have a 3rd condition (mandatory or a MatchAll), you can create a
bool query with :
Must -> Your Mandatory Query or MatchAll
Should -> TermQuery on "a"
Should -> TermQuery on "b"

It should work. Or I did not fully understand your use case.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 08:16, azi <azi...@gmail.com <javascript:>> a écrit :

Thanks David.
But I missed a condition in my earlier post.
I also want documents in return which doesn't have any of the tag a & b.
Which simply means that I want to match a & b only if those are there.
This I don't think can be modeled in the bool query you have suggested.

-Azitabh

On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:

You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher
score.

See
Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi azi...@gmail.com a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd
and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value
of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd
and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

--

--

Ok. I think I understand now.
You want to get docs that not contain a but you don't want to get docs when a is
not abcd.

I think you should give a look at the MultiMatch Query:
Elasticsearch Platform — Find real-time answers at scale | Elastic
http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query.html

David.

Le 6 novembre 2012 à 08:44, azi azitabh@gmail.com a écrit :

Should means at least one(or otherwise mentioned) of the conditions specified
should match.
So If I say:
should a=abcd
should b=wzyz

This will give me all documents which match the condition (the value of 'a'
is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and tag 'b'
doesn't exist) or (tag a doesn't exist and the value of 'b' is wxyz).

But what I want in return is all documents which match the condition (the
value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is
abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b'
is wxyz) or (tag 'a' doesn't exist and tag 'b' doesn't exist).

Correct me if I am wrong.

-Azitabh

On Tuesday, 6 November 2012 12:55:36 UTC+5:30, David Pilato wrote:

"Should" means that the query is not mandatory.
If you have a 3rd condition (mandatory or a MatchAll), you can create a
bool query with :
Must -> Your Mandatory Query or MatchAll
Should -> TermQuery on "a"
Should -> TermQuery on "b"

It should work. Or I did not fully understand your use case.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 08:16, azi < azi...@gmail.com> a écrit :

   > > >        Thanks David.
   But I missed a condition in my earlier post.
   I also want documents in return which doesn't have any of the tag a

& b.
Which simply means that I want to match a & b only if those are
there.
This I don't think can be modeled in the bool query you have
suggested.

   -Azitabh

   On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:
     > > > >          You can wrap 2 queries in a Bool Query with
     > > > > should clauses.
     That means that the doc which hit the two queries will have an

higher score.

     See

Elasticsearch Platform — Find real-time answers at scale | Elastic

     <http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html>
     --
     David ;-)

http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

     Le 6 nov. 2012 à 07:39, azi <

http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
azi...@gmail.com> a écrit :

         > > > > >              Lets say I have a set of document
         > > > > > which have a-z as keys.
         And I am firing this term query:
         curl -X GET

localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

         This will return me all the documents for which the value

of 'a' is abcd and the value of 'b' is wxyz.
But, what if I want all the such documents in return for
which (the value of 'a' is abcd and the value of 'b' is wxyz) or (the
value of 'a' is abcd and tag 'b' doesn't exist) or (tag a doesn't
exist and the value of 'b' is wxyz).

         Is this possible.

         Thanks In Advance
         -Azitabh



         --



     > > > >        > > > 
   --

--

--
David Pilato
http://www.scrutmydocs.org/
http://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

Thanks David!
But multi_search will only help me in searching a particular text in
multiple fields.
I don't think this will help me solve the problem I previously stated.
First of all, I don't have a common text to search in the fields a & b. And
second, It won;t match the documents where neither a nor b is present even
if I had one.

On Tuesday, 6 November 2012 14:11:57 UTC+5:30, David Pilato wrote:

Ok. I think I understand now.
You want to get docs that not contain a but you don't want to get docs
when a is not abcd.

I think you should give a look at the MultiMatch Query:
Elasticsearch Platform — Find real-time answers at scale | Elastic

David.

Le 6 novembre 2012 à 08:44, azi <azi...@gmail.com <javascript:>> a
écrit :

Should means at least one(or otherwise mentioned) of the conditions
specified should match.
So If I say:
should a=abcd
should b=wzyz

This will give me all documents which match the condition (the value of
'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and
tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

But what I want in return is all documents which match the condition (the
value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is
abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of
'b' is wxyz) or (tag 'a' doesn't exist and tag 'b' doesn't exist).

Correct me if I am wrong.

-Azitabh

On Tuesday, 6 November 2012 12:55:36 UTC+5:30, David Pilato wrote:

"Should" means that the query is not mandatory.
If you have a 3rd condition (mandatory or a MatchAll), you can create a
bool query with :
Must -> Your Mandatory Query or MatchAll
Should -> TermQuery on "a"
Should -> TermQuery on "b"

It should work. Or I did not fully understand your use case.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 08:16, azi < azi...@gmail.com> a écrit :

Thanks David.
But I missed a condition in my earlier post.
I also want documents in return which doesn't have any of the tag a & b.
Which simply means that I want to match a & b only if those are there.
This I don't think can be modeled in the bool query you have suggested.

-Azitabh

On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:

You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher
score.

See
Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi <http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
azi...@gmail.com> a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd
and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value
of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd
and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

--

--

--
David Pilato
http://www.scrutmydocs.org/
http://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

I think you can simplify your expression to (a=abcd OR a doesn't exist) AND
(b=wxyz OR b doesn't exist), which can be translated into the following
query:

{
"query" : {
"constant_score" : {
"filter" : {
"and" : [
{
"or": [
{
"term": {"a" : "abcd"}
},
{
"missing": {"field": "a"}
}
]
},
{
"or": [
{
"term": {"b" : "wxyz"}
},
{
"missing": {"field": "b"}
}
]
}
]
}
}
}
}

On Tuesday, November 6, 2012 9:59:38 AM UTC-5, azi wrote:

Thanks David!
But multi_search will only help me in searching a particular text in
multiple fields.
I don't think this will help me solve the problem I previously stated.
First of all, I don't have a common text to search in the fields a & b.
And second, It won;t match the documents where neither a nor b is present
even if I had one.

On Tuesday, 6 November 2012 14:11:57 UTC+5:30, David Pilato wrote:

Ok. I think I understand now.
You want to get docs that not contain a but you don't want to get docs
when a is not abcd.

I think you should give a look at the MultiMatch Query:
Elasticsearch Platform — Find real-time answers at scale | Elastic

David.

Le 6 novembre 2012 à 08:44, azi azi...@gmail.com a écrit :

Should means at least one(or otherwise mentioned) of the conditions
specified should match.
So If I say:
should a=abcd
should b=wzyz

This will give me all documents which match the condition (the value of
'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and
tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

But what I want in return is all documents which match the condition (the
value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is
abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of
'b' is wxyz) or (tag 'a' doesn't exist and tag 'b' doesn't exist).

Correct me if I am wrong.

-Azitabh

On Tuesday, 6 November 2012 12:55:36 UTC+5:30, David Pilato wrote:

"Should" means that the query is not mandatory.
If you have a 3rd condition (mandatory or a MatchAll), you can create a
bool query with :
Must -> Your Mandatory Query or MatchAll
Should -> TermQuery on "a"
Should -> TermQuery on "b"

It should work. Or I did not fully understand your use case.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 08:16, azi < azi...@gmail.com> a écrit :

Thanks David.
But I missed a condition in my earlier post.
I also want documents in return which doesn't have any of the tag a & b.
Which simply means that I want to match a & b only if those are there.
This I don't think can be modeled in the bool query you have suggested.

-Azitabh

On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:

You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher
score.

See
Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi <http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
azi...@gmail.com> a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd
and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the value
of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd
and tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

--

--

--
David Pilato
http://www.scrutmydocs.org/
http://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

Thanks a ton Igor!
This is what I was looking for. Restructuring isn't a problem. I just
didn't know about the missing filter.

Thanks Again
-Azitabh

On Wednesday, 7 November 2012 05:10:12 UTC+5:30, Igor Motov wrote:

I think you can simplify your expression to (a=abcd OR a doesn't exist)
AND (b=wxyz OR b doesn't exist), which can be translated into the following
query:

{
"query" : {
"constant_score" : {
"filter" : {
"and" : [
{
"or": [
{
"term": {"a" : "abcd"}
},
{
"missing": {"field": "a"}
}
]
},
{
"or": [
{
"term": {"b" : "wxyz"}
},
{
"missing": {"field": "b"}
}
]
}
]
}
}
}
}

On Tuesday, November 6, 2012 9:59:38 AM UTC-5, azi wrote:

Thanks David!
But multi_search will only help me in searching a particular text in
multiple fields.
I don't think this will help me solve the problem I previously stated.
First of all, I don't have a common text to search in the fields a & b.
And second, It won;t match the documents where neither a nor b is present
even if I had one.

On Tuesday, 6 November 2012 14:11:57 UTC+5:30, David Pilato wrote:

Ok. I think I understand now.
You want to get docs that not contain a but you don't want to get docs
when a is not abcd.

I think you should give a look at the MultiMatch Query:
Elasticsearch Platform — Find real-time answers at scale | Elastic

David.

Le 6 novembre 2012 à 08:44, azi azi...@gmail.com a écrit :

Should means at least one(or otherwise mentioned) of the conditions
specified should match.
So If I say:
should a=abcd
should b=wzyz

This will give me all documents which match the condition (the value of
'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is abcd and
tag 'b' doesn't exist) or (tag a doesn't exist and the value of 'b' is
wxyz).

But what I want in return is all documents which match the condition
(the value of 'a' is abcd and the value of 'b' is wxyz) or (the value of
'a' is abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the
value of 'b' is wxyz) or (tag 'a' doesn't exist and tag 'b' doesn't exist).

Correct me if I am wrong.

-Azitabh

On Tuesday, 6 November 2012 12:55:36 UTC+5:30, David Pilato wrote:

"Should" means that the query is not mandatory.
If you have a 3rd condition (mandatory or a MatchAll), you can create a
bool query with :
Must -> Your Mandatory Query or MatchAll
Should -> TermQuery on "a"
Should -> TermQuery on "b"

It should work. Or I did not fully understand your use case.

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 08:16, azi < azi...@gmail.com> a écrit :

Thanks David.
But I missed a condition in my earlier post.
I also want documents in return which doesn't have any of the tag a & b.
Which simply means that I want to match a & b only if those are there.
This I don't think can be modeled in the bool query you have suggested.

-Azitabh

On Tuesday, 6 November 2012 12:38:55 UTC+5:30, David Pilato wrote:

You can wrap 2 queries in a Bool Query with should clauses.

That means that the doc which hit the two queries will have an higher
score.

See
Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 nov. 2012 à 07:39, azi <http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
azi...@gmail.com> a écrit :

Lets say I have a set of document which have a-z as keys.
And I am firing this term query:
curl -X GET localhost:9200/memphis/pincode/_search?pretty=json -d
'{"query":{"term":{"a":"abcd", "b":"wxyz"}}}'

This will return me all the documents for which the value of 'a' is abcd
and the value of 'b' is wxyz.
But, what if I want all the such documents in return for which (the
value of 'a' is abcd and the value of 'b' is wxyz) or (the value of 'a' is
abcd and tag 'b' doesn't exist) or (tag a doesn't exist and the value of
'b' is wxyz).

Is this possible.

Thanks In Advance
-Azitabh

--

--

--

--
David Pilato
http://www.scrutmydocs.org/
http://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--