# Search a specific document?

**URL:** <https://discuss.elastic.co/t/search-a-specific-document/9993>\
**Category:** Elasticsearch\
**Created:** [December 7, 2012, 8:59pm UTC](https://discuss.elastic.co/t/search-a-specific-document/9993 "2012-12-07T20:59:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Zed](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@A\_Zed](https://discuss.elastic.co/u/A_Zed)\
**Post date:** [December 7, 2012, 8:59pm UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/1 "2012-12-07T20:59:26Z")

</div>

Is it possible to run a query against a specific document? I have the doc  
ID and the query; I'd like to just query that document.

Thanks!

--

---

<div class="post-metadata">

**Author:** ![A\_Zed](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@A\_Zed](https://discuss.elastic.co/u/A_Zed)\
**Post date:** [December 7, 2012, 9:04pm UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/2 "2012-12-07T21:04:18Z")

</div>

Actually, let me clarify: I just want the terms highlighted in the  
document, if there's a match.  
I could do it via JS in the client, but maybe ES is faster....

On Friday, December 7, 2012 12:59:26 PM UTC-8, A Zed wrote:

> Is it possible to run a query against a specific document? I have the doc  
> ID and the query; I'd like to just query that document.
> 
> Thanks!

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 7, 2012, 9:56pm UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/3 "2012-12-07T21:56:09Z")

</div>

Have you seen highlighting option in Search API  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/highlighting.html) ?

On Friday, December 7, 2012 4:04:18 PM UTC-5, A Zed wrote:

> Actually, let me clarify: I just want the terms highlighted in the  
> document, if there's a match.  
> I could do it via JS in the client, but maybe ES is faster....
> 
> On Friday, December 7, 2012 12:59:26 PM UTC-8, A Zed wrote:
> 
> > Is it possible to run a query against a specific document? I have the doc  
> > ID and the query; I'd like to just query that document.
> > 
> > Thanks!

--

---

<div class="post-metadata">

**Author:** ![A\_Zed](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@A\_Zed](https://discuss.elastic.co/u/A_Zed)\
**Post date:** [December 7, 2012, 9:58pm UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/4 "2012-12-07T21:58:40Z")

</div>

Yes I have. If I am able to search a specific doc, then I can use the  
highlight option too.

On Friday, December 7, 2012 1:56:09 PM UTC-8, Igor Motov wrote:

> Have you seen highlighting option in Search API  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/highlighting.html)?
> 
> On Friday, December 7, 2012 4:04:18 PM UTC-5, A Zed wrote:
> 
> > Actually, let me clarify: I just want the terms highlighted in the  
> > document, if there's a match.  
> > I could do it via JS in the client, but maybe ES is faster....
> > 
> > On Friday, December 7, 2012 12:59:26 PM UTC-8, A Zed wrote:
> > 
> > > Is it possible to run a query against a specific document? I have the  
> > > doc ID and the query; I'd like to just query that document.
> > > 
> > > Thanks!

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 7, 2012, 10:02pm UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/5 "2012-12-07T22:02:10Z")

</div>

How about ids  
filter? [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/ids-filter.html)

On Friday, December 7, 2012 4:58:40 PM UTC-5, A Zed wrote:

> Yes I have. If I am able to search a specific doc, then I can use the  
> highlight option too.
> 
> On Friday, December 7, 2012 1:56:09 PM UTC-8, Igor Motov wrote:
> 
> > Have you seen highlighting option in Search API  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/highlighting.html)?
> > 
> > On Friday, December 7, 2012 4:04:18 PM UTC-5, A Zed wrote:
> > 
> > > Actually, let me clarify: I just want the terms highlighted in the  
> > > document, if there's a match.  
> > > I could do it via JS in the client, but maybe ES is faster....
> > > 
> > > On Friday, December 7, 2012 12:59:26 PM UTC-8, A Zed wrote:
> > > 
> > > > Is it possible to run a query against a specific document? I have the  
> > > > doc ID and the query; I'd like to just query that document.
> > > > 
> > > > Thanks!

--

---

<div class="post-metadata">

**Author:** ![pellyadolfo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pellyadolfo/32/1879_2.png) [@pellyadolfo](https://discuss.elastic.co/u/pellyadolfo)\
**Post date:** [December 23, 2013, 4:39am UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/6 "2013-12-23T04:39:23Z")

</div>

According to what has been said in this thread to fetch only one document,  
I have tested the following query trying to highlight just one document:

SearchResponse response2 = getClient().prepareSearch()  
.setIndices("myindex")  
.setTypes("mytype")  
.setQuery(QueryBuilders  
.boolQuery()  
.should(QueryBuilders.matchQuery("2C", "house"))  
)

- .setFilter(FilterBuilders.idsFilter("ve0"))\*  
.addHighlightedField("2C", 250, 1)  
.execute()  
.actionGet();

System.out.println("Returned " + response2.getHits().getTotalHits() + "  
results");

However, the query produces zero results.

By commenting out the line

\*//.setFilter(FilterBuilders.idsFilter("ve0")) \*

10 results are generated as expected.

The id specified is correct. So, is it a bug or a misuse of idsFilter()?

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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/411fda5b-d0d3-41dd-9867-cfac05e49560%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/411fda5b-d0d3-41dd-9867-cfac05e49560%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![pellyadolfo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pellyadolfo/32/1879_2.png) [@pellyadolfo](https://discuss.elastic.co/u/pellyadolfo)\
**Post date:** [December 23, 2013, 5:15am UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/7 "2013-12-23T05:15:34Z")

</div>

I have just got my answer from fix to this bug

> <https://github.com/elastic/elasticsearch/issues/2695>

which contains a TestCase

> <https://github.com/elastic/elasticsearch/commit/8ab602ec810fefec1e84afe041aaab784ec594ce>

where proper syntax is:

.setFilter(FilterBuilders.idsFilter("vertex").ids("ve0"))

and document is now returned.

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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3cd7f32a-3989-45ea-ad42-96ad5307e10b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3cd7f32a-3989-45ea-ad42-96ad5307e10b%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:59am UTC](https://discuss.elastic.co/t/search-a-specific-document/9993/8 "2017-07-06T01:59:40Z")

</div>


