Beginners Query Questions

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.
  1. How are filters used in a way that is different from a boolean AND
    search?

I'm very new to ElasticSearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Hi,

On Thu, Feb 3, 2011 at 1:39 PM, dalesrob daviroberts@gmail.com wrote:

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.

Term queries does not perform any analysis (
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_query/).
Thus they are for exact matches.
However, field query (
Query DSL | Elasticsearch Guide [8.11] | Elastic)
uses analysis that is setup for this field (or default).

  1. How are filters used in a way that is different from a boolean AND
    search?

Filters do no scoring. So if you can use filter instead of query then you
probably should (much faster and can be cached).

I'm very new to Elasticsearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Regards,
Lukas

Just looking at this answer, do boolean query and filtered guarantee same
result?

On Thu, Feb 3, 2011 at 2:08 PM, Lukáš Vlček lukas.vlcek@gmail.com wrote:

Hi,

On Thu, Feb 3, 2011 at 1:39 PM, dalesrob daviroberts@gmail.com wrote:

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.

Term queries does not perform any analysis (
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_query/).
Thus they are for exact matches.
However, field query (
Query DSL | Elasticsearch Guide [8.11] | Elastic)
uses analysis that is setup for this field (or default).

  1. How are filters used in a way that is different from a boolean AND
    search?

Filters do no scoring. So if you can use filter instead of query then you
probably should (much faster and can be cached).

I'm very new to Elasticsearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Regards,
Lukas

I ask because with the same set of data, this query:

{

"from" : 0, size: 100,

"query" : {

    "bool" : {

        "must" : {

           "fuzzy" : {

   "_all" : {

        "value" : "lacie"

    }

}

        },

        "must" : {

           "fuzzy" : {

   "_all" : {

        "value" : "disco"

    }

}

        }

    }

}

}

Returns:

"max_score": 1.0678896,

"total": 1830

Whereas if I use this query:

{

"from" : 0, size: 100,

"query" : {

    "fuzzy" : {

   "_all" : {

        "value" : "lacie"

    }

},

"filtered" : {

"query" : {

           "fuzzy" : {

   "_all" : {

        "value" : "disco"

    }

 }

        }

    }

}

Then I get many more results:

"max_score": 3.9756753,

"total": 9825

Is this the expected behaviour?

Thanks.

On Thu, Feb 3, 2011 at 2:54 PM, Enrique Medina Montenegro <
e.medina.m@gmail.com> wrote:

Just looking at this answer, do boolean query and filtered guarantee same
result?

On Thu, Feb 3, 2011 at 2:08 PM, Lukáš Vlček lukas.vlcek@gmail.com wrote:

Hi,

On Thu, Feb 3, 2011 at 1:39 PM, dalesrob daviroberts@gmail.com wrote:

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.

Term queries does not perform any analysis (
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_query/).
Thus they are for exact matches.
However, field query (
Query DSL | Elasticsearch Guide [8.11] | Elastic)
uses analysis that is setup for this field (or default).

  1. How are filters used in a way that is different from a boolean AND
    search?

Filters do no scoring. So if you can use filter instead of query then you
probably should (much faster and can be cached).

I'm very new to Elasticsearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Regards,
Lukas

I think your second query is not correct.

http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/How
about this:

"query" : {
"filtered" : {
"query" : { ... your fuzzy query #1 ...},
"filter" : {
"query" : { ... your fuzzy query #2 ...}
}
}
}

In other words combination of
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/query_filter/

However, I did not try this myself...

Regards,
Lukas

On Thu, Feb 3, 2011 at 2:59 PM, Enrique Medina Montenegro <
e.medina.m@gmail.com> wrote:

I ask because with the same set of data, this query:

{

"from" : 0, size: 100,

"query" : {

    "bool" : {

        "must" : {

           "fuzzy" : {

   "_all" : {

        "value" : "lacie"

    }

}

        },

        "must" : {

           "fuzzy" : {

   "_all" : {

        "value" : "disco"

    }

}

        }

    }

}

}

Returns:

"max_score": 1.0678896,

"total": 1830

Whereas if I use this query:

{

"from" : 0, size: 100,

"query" : {

    "fuzzy" : {

   "_all" : {

        "value" : "lacie"

    }

},

"filtered" : {

"query" : {

           "fuzzy" : {

   "_all" : {

        "value" : "disco"

    }

 }

        }

    }

}

Then I get many more results:

"max_score": 3.9756753,

"total": 9825

Is this the expected behaviour?

Thanks.

On Thu, Feb 3, 2011 at 2:54 PM, Enrique Medina Montenegro <
e.medina.m@gmail.com> wrote:

Just looking at this answer, do boolean query and filtered guarantee same
result?

On Thu, Feb 3, 2011 at 2:08 PM, Lukáš Vlček lukas.vlcek@gmail.comwrote:

Hi,

On Thu, Feb 3, 2011 at 1:39 PM, dalesrob daviroberts@gmail.com wrote:

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.

Term queries does not perform any analysis (
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_query/).
Thus they are for exact matches.
However, field query (
Query DSL | Elasticsearch Guide [8.11] | Elastic)
uses analysis that is setup for this field (or default).

  1. How are filters used in a way that is different from a boolean AND
    search?

Filters do no scoring. So if you can use filter instead of query then you
probably should (much faster and can be cached).

I'm very new to Elasticsearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Regards,
Lukas

Yes, you're right, it was not properly configured. So now the filter
approach is:

{

"from" : 0, size: 100,

"query" : {

"filtered" : {

"query" : {

     "fuzzy" : {

    "_all" : {

         "value" : "lacie"

     }

}

},

"filter" : {

"query" : {

            "fuzzy" : {

    "_all" : {

          "value" : "disco"

      }

  }

         }

}

    }

}

}

which gives a result of 1826, just 4 less than the other one.

Should it still be the same exact result or that deviation is fine?

And BTW, what was my previous query doing then?

(Original purpose was to find "disco lacie" as the search string).

Thanks.

On Thu, Feb 3, 2011 at 3:17 PM, Lukáš Vlček lukas.vlcek@gmail.com wrote:

I think your second query is not correct.

http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/How
about this:

"query" : {
"filtered" : {
"query" : { ... your fuzzy query #1 ...},
"filter" : {
"query" : { ... your fuzzy query #2 ...}
}
}
}

In other words combination of

http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/filtered_query/

http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/query_filter/

However, I did not try this myself...

Regards,
Lukas

On Thu, Feb 3, 2011 at 2:59 PM, Enrique Medina Montenegro <
e.medina.m@gmail.com> wrote:

I ask because with the same set of data, this query:

{

"from" : 0, size: 100,

"query" : {

    "bool" : {

        "must" : {

           "fuzzy" : {

   "_all" : {

        "value" : "lacie"

    }

}

        },

        "must" : {

           "fuzzy" : {

   "_all" : {

        "value" : "disco"

    }

}

        }

    }

}

}

Returns:

"max_score": 1.0678896,

"total": 1830

Whereas if I use this query:

{

"from" : 0, size: 100,

"query" : {

    "fuzzy" : {

   "_all" : {

        "value" : "lacie"

    }

},

"filtered" : {

"query" : {

           "fuzzy" : {

   "_all" : {

        "value" : "disco"

    }

 }

        }

    }

}

Then I get many more results:

"max_score": 3.9756753,

"total": 9825

Is this the expected behaviour?

Thanks.

On Thu, Feb 3, 2011 at 2:54 PM, Enrique Medina Montenegro <
e.medina.m@gmail.com> wrote:

Just looking at this answer, do boolean query and filtered guarantee same
result?

On Thu, Feb 3, 2011 at 2:08 PM, Lukáš Vlček lukas.vlcek@gmail.comwrote:

Hi,

On Thu, Feb 3, 2011 at 1:39 PM, dalesrob daviroberts@gmail.com wrote:

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.

Term queries does not perform any analysis (
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_query/).
Thus they are for exact matches.
However, field query (
Query DSL | Elasticsearch Guide [8.11] | Elastic)
uses analysis that is setup for this field (or default).

  1. How are filters used in a way that is different from a boolean AND
    search?

Filters do no scoring. So if you can use filter instead of query then
you probably should (much faster and can be cached).

I'm very new to Elasticsearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Regards,
Lukas

Hi Lukas,

Thanks for the reply, does the same apply to the Lucence syntax "Query
String" Queries usings booleans? Would it be better to use (cached)
filters?

thanks,

David.

On Feb 3, 1:08 pm, Lukáš Vlček lukas.vl...@gmail.com wrote:

Hi,

On Thu, Feb 3, 2011 at 1:39 PM, dalesrob davirobe...@gmail.com wrote:

Hi,

I'm just looking at the different sorts of queries I can use with the
Java API and I have a couple of questions to clear up.

  1. What is a termQuery used for, how does it differ from a fieldQuery
  • initially I though termQueries were for exact quoted "this exact
    expression" type queries, but now I'm not so sure.

Term queries does not perform any analysis (http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/te...).
Thus they are for exact matches.
However, field query (http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/fi...)
uses analysis that is setup for this field (or default).

  1. How are filters used in a way that is different from a boolean AND
    search?

Filters do no scoring. So if you can use filter instead of query then you
probably should (much faster and can be cached).

I'm very new to Elasticsearch so any detailled answers to enlighten a
newbie would be much appreciated.

thanks,

David

Regards,
Lukas