Hi Steve, Thank you very much for your inputs. Yes, I do know the aliasing mechanism offered in Solr. I think the whole question boils down to one thing: how much do you know about the data being stored -- and sometimes you know nothing about that.
In some cases, you have to provide a generic solution for users to store and query their own data. With Solr / Lucene backing your storage, you can easily expose a restricted (but still powerful) subset of the Solr / Lucene query syntax for querying user-defined data. Things however would start getting complicated if you have to tell your customers, that the field you loaded as "foo" must be referred as "foo_s" and the field you loaded "bar" must be referred as "bar_i", since it contains a number and so on... Implementing the mapping in your application would be overly complex, as you would have to maintain a mapping between the internal representation ("foo_s") and the query interface ("foo") and alias results from the internal format to the format visible to the user ("foo_s" --> "foo"). I think you get the idea. I like the way Solr can use the name for specifying type: having a configuration option (either global or at collection level), which tells Solr to handle type postfixes slightly differently and strip the type prefix automatically would be perfectly enough for this use-case. Imagine the following approach: if configured so, Solr would still create the field based on the type postfix, but would strip it from the name: for example, if a document is inserted with the field "foo_s" and "bar_i", Solr could create a string field named "foo" and a numeric field "bar". I think this solution would be both backwards compatible (has to be explicitly enabled) and relatively simple to implement in the Solr code base. I have created a Jira issue for the feature request: https://issues.apache.org/jira/browse/SOLR-9150 What do you think? Thanks, Peter 2016-05-19 15:30 GMT+02:00 Steve Rowe <sar...@gmail.com>: > Peter, > > It’s an interesting idea. Could you make a Solr JIRA? > > I don’t know where the field type specification would go, but providing a > mechanism to specify field type for previously non-existent fields, outside > of the field names themselves, seems useful. > > In the meantime, do you know about field aliasing? > > 1. You can get results back that rename fields to whatever you want: see > the section “Field Name Aliases” here: < > https://cwiki.apache.org/confluence/display/solr/Common+Query+Parameters>. > > 2. On the query side, eDisMax can perform aliasing so that user-specified > field names in queries get mapped to one or more indexed fields: look for > “alias” in < > https://cwiki.apache.org/confluence/display/solr/The+Extended+DisMax+Query+Parser > >. > > -- > Steve > www.lucidworks.com > > > On May 19, 2016, at 4:43 AM, Horváth Péter Gergely < > peter.gergely.horv...@gmail.com> wrote: > > > > Hi Steve, > > > > Yes, I know the schema API, however I do not want to specify the field > type > > problematically for every single field. > > > > I would like to be able to specify the field type when it is being added > > (similar to the name postfixes, but without affecting the field names). > > > > Thanks, > > Peter > > > > > > 2016-05-17 17:08 GMT+02:00 Steve Rowe <sar...@gmail.com>: > > > >> Hi Peter, > >> > >> Are you familiar with the Schema API?: < > >> https://cwiki.apache.org/confluence/display/solr/Schema+API> > >> > >> You can use it to create fields, field types, etc. prior to ingesting > your > >> data. > >> > >> -- > >> Steve > >> www.lucidworks.com > >> > >>> On May 17, 2016, at 11:05 AM, Horváth Péter Gergely < > >> peter.gergely.horv...@gmail.com> wrote: > >>> > >>> Hi All, > >>> > >>> By default Solr allows you to define the type of a dynamic field by > >>> appending a post-fix to the name itself. E.g. creating a color_s field > >>> instructs Solr to create a string field. My understanding is that if we > >> do > >>> this, all queries must refer the post-fixed field name as well. So > >>> instead of a query like color:"red", we will have to write something > like > >>> color_s:"red" -- and so on for other field types as well. > >>> > >>> I am wondering if it is possible to specify the data type used for a > >> field > >>> in Solr 6.0.0, without having to modify the field name. (Or at least > in a > >>> way that would allow us to use the original field name) Do you have any > >>> idea, how to achieve this? I am fine, if we have to specify the field > >> type > >>> during the insertion of a document, however, I do not want to keep > using > >>> post-fixes while running queries... > >>> > >>> Thanks, > >>> Peter > >> > >> > >