Getting the field which matched the document

Hi,

I would like to explain a quick scenario here. Say we have a document which
has fields name and address

Document 1
name: Vikas
address: West Patel Nagar

Document 2
name: Joe
address: Vikas Puri

Now if i do a simple search like this
curl'http://localhost:9200/blog/post/_search?q=Vikas&pretty=true'

It pulls back both the documents. But, is there a way to know which
document was pulled back due to what field? I have read something about
highlighting but I am not sure if that would help here.

On the basis of the field on which the document is matched we would like to
show it differently.

Regards | Vikas
www.knoldus.com

--
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.

There's no easy way to know this. You could use highlighting or explain,
but those are essentially hacks.

The correct way to do this would be to issue two searches, one against the
name field and one against the address field.

clint

On Fri, Apr 12, 2013 at 3:31 PM, Vikas Hazrati vikas@knoldus.com wrote:

Hi,

I would like to explain a quick scenario here. Say we have a document
which has fields name and address

Document 1
name: Vikas
address: West Patel Nagar

Document 2
name: Joe
address: Vikas Puri

Now if i do a simple search like this curl'
http://localhost:9200/blog/post/_search?q=Vikas&pretty=true'

It pulls back both the documents. But, is there a way to know which
document was pulled back due to what field? I have read something about
highlighting but I am not sure if that would help here.

On the basis of the field on which the document is matched we would like
to show it differently.

Regards | Vikas
www.knoldus.com

--
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.

--
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.

Hi Clint,

Thanks for your response. I would have loved to fire 2 queries had the
scenario got just 2 fields to work against. We have tens if not scores
against which a record could match. Hence, I was wondering if there is a
better solution. I would check out explain as well.

Is this a problem that other people had to deal with as well?

Regards | Vikas

On Sunday, April 14, 2013 3:48:27 PM UTC+5:30, Clinton Gormley wrote:

There's no easy way to know this. You could use highlighting or explain,
but those are essentially hacks.

The correct way to do this would be to issue two searches, one against the
name field and one against the address field.

clint

On Fri, Apr 12, 2013 at 3:31 PM, Vikas Hazrati <vi...@knoldus.com<javascript:>

wrote:

Hi,

I would like to explain a quick scenario here. Say we have a document
which has fields name and address

Document 1
name: Vikas
address: West Patel Nagar

Document 2
name: Joe
address: Vikas Puri

Now if i do a simple search like this curl'
http://localhost:9200/blog/post/_search?q=Vikas&pretty=true'

It pulls back both the documents. But, is there a way to know which
document was pulled back due to what field? I have read something about
highlighting but I am not sure if that would help here.

On the basis of the field on which the document is matched we would like
to show it differently.

Regards | Vikas
www.knoldus.com

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.

On the basis of the field on which the document is matched we would like
to show it differently.

This seems vague. What exactly is it you want to achieve? Might be you
can have the query return the entire document, then resolve which
field was matched in code.

--
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.

Right, probably it has some ambiguity. What you suggest can be done but I
was wondering if the API would hep me in some way. So there would be 87
fields in the document. As a wide search. the user potentially searches for
""

Based on whether the field which matches was an "address" or if it was a
"magician name" we would like to alter the workflow.

So the crux of the matter is to get which field matched. I hope that
clarifies it a bit

On Monday, April 15, 2013 2:31:46 PM UTC+5:30, iftekhar wrote:

On the basis of the field on which the document is matched we would
like
to show it differently.

This seems vague. What exactly is it you want to achieve? Might be you
can have the query return the entire document, then resolve which
field was matched in code.

--
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.

On Mon, Apr 15, 2013 at 1:13 PM, Vikas Hazrati vikas@knoldus.com wrote:

Right, probably it has some ambiguity. What you suggest can be done but I
was wondering if the API would hep me in some way. So there would be 87
fields in the document. As a wide search. the user potentially searches for
""

Based on whether the field which matches was an "address" or if it was a
"magician name" we would like to alter the workflow.

So the crux of the matter is to get which field matched. I hope that
clarifies it a bit

Indeed.

You can consider building multiple indices, one with the authoritative
data you're querying on, and another being an index that specializes
in helping you categorize tokens. So it would contain a mapping of
token to "search string type," so "123 Baker Street" => "Address," and
"Mandrake" => "Magician." Then do a mutli-query to your cluster, one
for string types, and one for the actual results.

Alternatively, each document can contain all the tokens present in
that document, mapping to the searchstring type. Just get that back on
each query.

This gets confusing, though, if "Mandrake" matches magician, and
matches on, say, "Mandrake Street." That's a slightly different
problem, though, because if a document contains the same token in two
types, ( e.g. {magician => "Mandrake", address => "123 Mandrake
Street"}), you'll need more business logic to handle those cases.

You might be trying to offload potentially non-trivial business logic
onto ES. You may need to look at solving the problem in another layer!

Hope it helps!

  • Ifty.

--
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.