Although being a total newbie, may be this question is pretty naive. I want to search my index based on the index. So I tried created a document with just one index, Name, and then want to search for that particular field.
I am doing this in process of trying to find out if I can update the fields of a document without actually deleting a document in lucene.
Thanks.
Lucene supports fielded data. When performing a search you can either specify a field, or use the default field. The field names and default field is implementation specific. You can search any field by typing the field name followed by a colon ":" and then the term you are looking for.
A query written in Lucene can be broken down into three parts: Field The ID or name of a specific container of information in a database. If a field is referenced in a query string, a colon ( : ) must follow the field name. Terms Items you would like to search for in a database.
BooleanQuery is used to search documents which are a result of multiple queries using AND, OR or NOT operators.
Elasticsearch is built over Lucene and provides a JSON based REST API to refer to Lucene features. Elasticsearch provides a distributed system on top of Lucene. A distributed system is not something Lucene is aware of or built for. Elasticsearch provides this abstraction of distributed structure.
You can search for words within a particular field with the colon syntax i.e. name:john
.
But because a lot of indexes just have one field you are going to want to search on, there is a default field, in case you just search for john
. You can set which field that is when you instanciate your QueryParser
QueryParser parser = new QueryParser(Version.LUCENE_30, "name", anAnalyzer);
Query q = parser.parse("john");
If you want to create your queries programmatically rather than parsing a user-entered query string, then you also have to specify the field explicitly, for example:
Query q = new TermQuery(new Term("name", "john"));
Links: Using fields in Lucene queries (Lucene Query Syntax) | QueryParser Javadoc | TermQuery Javadoc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With