= Analytics Expression Sources
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

Expression sources are the source of the data being aggregated in <<analytics.adoc#expressions,analytics expressions>>.

These sources can be either Solr fields indexed with docValues, or constants.

== Supported Field Types

The following <<field-types-included-with-solr.adoc#, Solr field types>> are supported.
Fields of these types can be either multi-valued and single-valued.

All fields used in analytics expressions *must* have <<docvalues.adoc#,docValues>> enabled.


// Since Trie* fields are deprecated as of 7.0, we should consider removing Trie* fields from this list...

[horizontal]
String::
    StrField
Boolean::
    BoolField
Integer::
    TrieIntField +
    IntPointField
Long::
    TrieLongField +
    LongPointField
Float::
    TrieFloatField +
    FloatPointField
Double::
    TrieDoubleField +
    DoublePointField
Date::
    TrieDateField +
    DatePointField

.Multi-valued Field De-duplication
[WARNING]
====
All multi-valued field types, except for PointFields, are de-duplicated, meaning duplicate values for the same field are removed during indexing.
In order to save duplicates, you must use PointField types.
====

== Constants

Constants can be included in expressions to use along side fields and functions. The available constants are shown below.
Constants do not need to be surrounded by any function to define them, they can be used exactly like fields in an expression.

=== Strings

There are two possible ways of specifying constant strings, as shown below.

* Surrounded by double quotes, inside the quotes both `"` and `\` must be escaped with a `\` character.
+
`"Inside of 'double' \\ \"quotes\""` \=> `Inside of 'double' \ "quotes"`
* Surrounded by single quotes, inside the quotes both `'` and `\` must be escaped with a `\` character.
+
`'Inside of "single" \\ \'quotes\''` \=> `Inside of "double" \ 'quotes'`

=== Dates

Dates can be specified in the same way as they are in Solr queries. Just use ISO-8601 format.
For more information, refer to the <<working-with-dates.adoc#,Working with Dates>> section.

* `2017-07-17T19:35:08Z`

=== Numeric

Any non-decimal number will be read as an integer, or as a long if it is too large for an integer. All decimal numbers will be read as doubles.

* `-123421`: Integer
* `800000000000`: Long
* `230.34`: Double
