Search multiple fields with “and” operator (but use fields' own analyzers)

ElasticSearch Version: 0.90.2

Here's the problem: I want to find documents in the index so that they:

  1. match all query tokens across multiple fields
  2. fields own analyzers are used

So if there are 4 documents:

{ "_id" : 1, "name" : "Joe Doe",     "mark" : "1", "message" : "Message 

First" }
{ "_id" : 2, "name" : "Ann", "mark" : "3", "message" : "Yesterday
Joe Doe got 1 for the message First"}
{ "_id" : 3, "name" : "Joe Doe", "mark" : "2", "message" : "Message
Second" }
{ "_id" : 4, "name" : "Dan Spencer", "mark" : "2", "message" : "Message
Third" }

And the query is "Joe First 1" it should find ids 1 and 2. I.e., it should
find documents which contain all the tokens from search query, no matter in
which fields they are (maybe all tokens are in one field, or maybe each
token is in its own field).

One solution would be to use elasticsearch "_all" field functionality: that
way it will merge all the fields I need (name, mark, message) into one and
I'll be able to query it with something like

"match": {
  "_all": {
    "query": "Joe First 1",
    "operator": "and"
  }
}

But this way I can specify analyzer for the "_all" field only. And I need
"name" and "message" fields to have different set of tokenizers/token
filters (let's say name will have phonetic analyzer and message will have
some stemming token filter).

Is there a way to do this?
Thanks.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

The only thing I have on my mind at the moment is to split query to terms
clientside (I know tokenizer will do it better but I can bear with some
inaccuracy) and make a query like this:
"query_string": {
"fields": [
"name",
"mark",
"message"
],
"query": "Joe AND First AND 1"
}

On Thursday, August 8, 2013 2:08:38 AM UTC+4, Max Ivanov wrote:

Elasticsearch Version: 0.90.2

Here's the problem: I want to find documents in the index so that they:

  1. match all query tokens across multiple fields
  2. fields own analyzers are used

So if there are 4 documents:

{ "_id" : 1, "name" : "Joe Doe",     "mark" : "1", "message" : "Message 

First" }
{ "_id" : 2, "name" : "Ann", "mark" : "3", "message" : "Yesterday
Joe Doe got 1 for the message First"}
{ "_id" : 3, "name" : "Joe Doe", "mark" : "2", "message" : "Message
Second" }
{ "_id" : 4, "name" : "Dan Spencer", "mark" : "2", "message" : "Message
Third" }

And the query is "Joe First 1" it should find ids 1 and 2. I.e., it should
find documents which contain all the tokens from search query, no matter in
which fields they are (maybe all tokens are in one field, or maybe each
token is in its own field).

One solution would be to use elasticsearch "_all" field functionality:
that way it will merge all the fields I need (name, mark, message) into one
and I'll be able to query it with something like

"match": {
  "_all": {
    "query": "Joe First 1",
    "operator": "and"
  }
}

But this way I can specify analyzer for the "_all" field only. And I need
"name" and "message" fields to have different set of tokenizers/token
filters (let's say name will have phonetic analyzer and message will have
some stemming token filter).

Is there a way to do this?
Thanks.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Query_string has option to specify default lofical operator to be used netween tokens default is OR but you can specify AND

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

use multi match query:

Le jeudi 8 août 2013 00:08:38 UTC+2, Max Ivanov a écrit :

Elasticsearch Version: 0.90.2

Here's the problem: I want to find documents in the index so that they:

  1. match all query tokens across multiple fields
  2. fields own analyzers are used

So if there are 4 documents:

{ "_id" : 1, "name" : "Joe Doe",     "mark" : "1", "message" : "Message 

First" }
{ "_id" : 2, "name" : "Ann", "mark" : "3", "message" : "Yesterday
Joe Doe got 1 for the message First"}
{ "_id" : 3, "name" : "Joe Doe", "mark" : "2", "message" : "Message
Second" }
{ "_id" : 4, "name" : "Dan Spencer", "mark" : "2", "message" : "Message
Third" }

And the query is "Joe First 1" it should find ids 1 and 2. I.e., it should
find documents which contain all the tokens from search query, no matter in
which fields they are (maybe all tokens are in one field, or maybe each
token is in its own field).

One solution would be to use elasticsearch "_all" field functionality:
that way it will merge all the fields I need (name, mark, message) into one
and I'll be able to query it with something like

"match": {
  "_all": {
    "query": "Joe First 1",
    "operator": "and"
  }
}

But this way I can specify analyzer for the "_all" field only. And I need
"name" and "message" fields to have different set of tokenizers/token
filters (let's say name will have phonetic analyzer and message will have
some stemming token filter).

Is there a way to do this?
Thanks.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

AlexR, I guess you meant one of the match or multi match queries, they both
have configurable logical operator, but it won't help (see below).

Damien, multi match query won't work, because it will produce a query to
match all tokens within each field (if AND logical operator is used),
or a query to match any token withinn any field (with OR logical
operator set).
So in my example, if the query is "Joe First 1" and multi match with AND
setting used,

{ "_id" : 2, "name" : "Ann",         "mark" : "3", "message" : "Yesterday 

Joe Doe got 1 for the message First"} will match
while
{ "_id" : 1, "name" : "Joe Doe", "mark" : "1", "message" : "Message
First" } won't

On Thursday, August 8, 2013 4:15:12 PM UTC+4, Damien Ferey wrote:

use multi match query:
Elasticsearch Platform — Find real-time answers at scale | Elastic

Le jeudi 8 août 2013 00:08:38 UTC+2, Max Ivanov a écrit :

Elasticsearch Version: 0.90.2

Here's the problem: I want to find documents in the index so that they:

  1. match all query tokens across multiple fields
  2. fields own analyzers are used

So if there are 4 documents:

{ "_id" : 1, "name" : "Joe Doe",     "mark" : "1", "message" : "Message 

First" }
{ "_id" : 2, "name" : "Ann", "mark" : "3", "message" : "Yesterday
Joe Doe got 1 for the message First"}
{ "_id" : 3, "name" : "Joe Doe", "mark" : "2", "message" : "Message
Second" }
{ "_id" : 4, "name" : "Dan Spencer", "mark" : "2", "message" : "Message
Third" }

And the query is "Joe First 1" it should find ids 1 and 2. I.e., it
should find documents which contain all the tokens from search query, no
matter in which fields they are (maybe all tokens are in one field, or
maybe each token is in its own field).

One solution would be to use elasticsearch "_all" field functionality:
that way it will merge all the fields I need (name, mark, message) into one
and I'll be able to query it with something like

"match": {
  "_all": {
    "query": "Joe First 1",
    "operator": "and"
  }
}

But this way I can specify analyzer for the "_all" field only. And I need
"name" and "message" fields to have different set of tokenizers/token
filters (let's say name will have phonetic analyzer and message will have
some stemming token filter).

Is there a way to do this?
Thanks.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I meant query_string see default_operator in http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query/

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

AlexR you're absolutely right, I overlooked default_operator parameter.
Problem solved :slight_smile:
Thank you!

On Thursday, August 8, 2013 11:03:10 PM UTC+4, AlexR wrote:

I meant query_string see default_operator in
Elasticsearch Platform — Find real-time answers at scale | Elastic

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.