Missing filter to check the existence of field and null_value

Hi All,

My Mapping example:

include Tire::Model::Search

Tire.index('account_1') do
create(
:mappings => {
:user => {
:properties => {
:name => { :type => :string, :boost => 10 },
:company_name => { :type => :string, :boost => 5 }
}
},
:comments => {
:properties => {
:description => { :type => :string, :boost => 5 }
}
}
}
)
end

In the above mapping I would like to filter search results with a
particular company_name. The company_name can be Null also (This is just an
example). As you can see the comments type doesn't have company_name field.
So, I have to use exists filter also.

search_key = 'test'
Tire.search [account_1] do
query do
filtered do
query { string search_key }
filter :or, { :not => { :exists => { :field =>
:company_name } } },
{ :term => { :company_name => 'test' } }
end
end
end

The above filter checks just the existence of company_name field or filters
exact company_name if exists. I want to add null_value check along with
this if company_name field exists.
I want to avoid the results where company_name is nil for the user type
along with the above filter.

Yours,

Vamsi Krishna O.

--

I think what you are looking for is actually called the missinghttp://www.elasticsearch.org/guide/reference/query-dsl/missing-filter.htmlfilter.

On Thursday, January 10, 2013 6:31:25 AM UTC-5, vamsi krishna wrote:

Hi All,

My Mapping example:

include Tire::Model::Search

Tire.index('account_1') do
create(
:mappings => {
:user => {
:properties => {
:name => { :type => :string, :boost => 10 },
:company_name => { :type => :string, :boost => 5 }
}
},
:comments => {
:properties => {
:description => { :type => :string, :boost => 5 }
}
}
}
)
end

In the above mapping I would like to filter search results with a
particular company_name. The company_name can be Null also (This is just an
example). As you can see the comments type doesn't have company_name field.
So, I have to use exists filter also.

search_key = 'test'
Tire.search [account_1] do
query do
filtered do
query { string search_key }
filter :or, { :not => { :exists => { :field => :company_name } } },
{ :term => { :company_name => 'test' } }
end
end
end

The above filter checks just the existence of company_name field or
filters exact company_name if exists. I want to add null_value check along
with this if company_name field exists.
I want to avoid the results where company_name is nil for the user type
along with the above filter.

Yours,

Vamsi Krishna O.

--

First of all sorry for asking the question using the Tire gem functions. I
should have posted the gist or curl example in elasticsearch group.

Thanks for the reply Igor.

Even missing filter is avoiding null values. Came to know that a field with
a null value simply isn't even stored.

Finally achieved it with the help of suggestion given by Tire gem owner
Karmi. I had to replace the null value in the document with mapping via the
null_value option, and then used the same filter.

On Tuesday, January 15, 2013 5:06:58 AM UTC+5:30, Igor Motov wrote:

I think what you are looking for is actually called the missinghttp://www.elasticsearch.org/guide/reference/query-dsl/missing-filter.htmlfilter.

On Thursday, January 10, 2013 6:31:25 AM UTC-5, vamsi krishna wrote:

Hi All,

My Mapping example:

include Tire::Model::Search

Tire.index('account_1') do
create(
:mappings => {
:user => {
:properties => {
:name => { :type => :string, :boost => 10 },
:company_name => { :type => :string, :boost => 5 }
}
},
:comments => {
:properties => {
:description => { :type => :string, :boost => 5 }
}
}
}
)
end

In the above mapping I would like to filter search results with a
particular company_name. The company_name can be Null also (This is just an
example). As you can see the comments type doesn't have company_name field.
So, I have to use exists filter also.

search_key = 'test'
Tire.search [account_1] do
query do
filtered do
query { string search_key }
filter :or, { :not => { :exists => { :field => :company_name } } },
{ :term => { :company_name => 'test' } }
end
end
end

The above filter checks just the existence of company_name field or
filters exact company_name if exists. I want to add null_value check along
with this if company_name field exists.
I want to avoid the results where company_name is nil for the user type
along with the above filter.

Yours,

Vamsi Krishna O.

--

The original requirement is that, I have documents one with the field
company_name - Test, other with out the field company_name and another with
company_name as NULL.

Now, from these documents, I need the results where company_name = Test or
company_name field doesn't exist. I don't need the document with
company_name = NULL.

On Tuesday, January 15, 2013 5:06:58 AM UTC+5:30, Igor Motov wrote:

I think what you are looking for is actually called the missinghttp://www.elasticsearch.org/guide/reference/query-dsl/missing-filter.htmlfilter.

On Thursday, January 10, 2013 6:31:25 AM UTC-5, vamsi krishna wrote:

Hi All,

My Mapping example:

include Tire::Model::Search

Tire.index('account_1') do
create(
:mappings => {
:user => {
:properties => {
:name => { :type => :string, :boost => 10 },
:company_name => { :type => :string, :boost => 5 }
}
},
:comments => {
:properties => {
:description => { :type => :string, :boost => 5 }
}
}
}
)
end

In the above mapping I would like to filter search results with a
particular company_name. The company_name can be Null also (This is just an
example). As you can see the comments type doesn't have company_name field.
So, I have to use exists filter also.

search_key = 'test'
Tire.search [account_1] do
query do
filtered do
query { string search_key }
filter :or, { :not => { :exists => { :field => :company_name } } },
{ :term => { :company_name => 'test' } }
end
end
end

The above filter checks just the existence of company_name field or
filters exact company_name if exists. I want to add null_value check along
with this if company_name field exists.
I want to avoid the results where company_name is nil for the user type
along with the above filter.

Yours,

Vamsi Krishna O.

--