# Native Lucene search - no fields in TopDocs

**URL:** <https://discourse.hibernate.org/t/native-lucene-search-no-fields-in-topdocs/6643>\
**Category:** Hibernate Search\
**Created:** [September 8, 2022, 4:12am UTC](https://discourse.hibernate.org/t/native-lucene-search-no-fields-in-topdocs/6643 "2022-09-08T04:12:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kraken](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@kraken](https://discourse.hibernate.org/u/kraken)\
**Post date:** [September 8, 2022, 4:12am UTC](https://discourse.hibernate.org/t/native-lucene-search-no-fields-in-topdocs/6643/1 "2022-09-08T04:12:30Z")

</div>

Hi.  
Could you expaint me why IndexReader returns me the documents with fields = 0?

Im using the version 6.1.2.Final

Thanks a lot.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/a/a2c5899727a4a2dff22e32d3df498abdb4d7bd5e.png)

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [September 8, 2022, 6:39am UTC](https://discourse.hibernate.org/t/native-lucene-search-no-fields-in-topdocs/6643/2 "2022-09-08T06:39:00Z")

</div>

I moved your message to a new topic.

Please don’t revive old topics of other people with a question of your own: just create a new topic.

As to your question… Only stored fields are returned by `IndexSearcher#doc`/`IndexReader#document`. See the javadoc of `IndexReader#document`:

> NOTE: only the content of a field is returned, if that field was stored during indexing.

You need to make sure that the content of fields is stored during indexing, which in the case of Hibernate Search means marking fields as projectable (`@GenericField(projectable = Projectable.YES)`). Of course you will need to reindex for these changes to take effect.

Also, you’re doing native Lucene stuff, and that’s going to get more complex as you run into corner cases. For example you won’t be able to (easily) retrieve the value of fields in nested documents.

I’d suggest you use the more user-friendly Hibernate Search APIs instead?

```java
EntityManager em = ...;
QueryBuilder queryBuilder = new QueryBuilder( new StandardAnalyzer() );
Query query1 = queryBuilder.createBooleanQuery( "title", term );
List<Document> documents = Search.session( em ).search( Product.class )
        .extension( LuceneExtension.get() )
        .select( f -> f.document() )
        .where( f -> f.fromLuceneQuery( query1 ) )
        .fetch( 10 );

```

That requires an `EntityManager`, which you seem to be trying to avoid, but I’m not sure you should: with most configurations, instantiating an `EntityManager` is almost neutral performance-wise as long as you don’t access the database, since the JDBC connection is retrieved on first access to the database (JPA query, persist, flush, …).

---

<div class="post-metadata">

**Author:** ![kraken](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@kraken](https://discourse.hibernate.org/u/kraken)\
**Post date:** [September 9, 2022, 2:23am UTC](https://discourse.hibernate.org/t/native-lucene-search-no-fields-in-topdocs/6643/3 "2022-09-09T02:23:52Z")

</div>

Problem solved, thanks. 👍
