Table of Contents
1. Introduction, download and installation of Apache Solr
2. Core kernel instance, IK tokenizer, Solr (stand-alone, cluster)
3. Solr basic commands (start, stop, system information)
4. Solr’s solrconfig.xml configuration and managed.schema mode
5. Solr Admin UI operations (XML, JSON add|modify|delete|query index)
6. Solr configures DataImport to import index data and IK word segmentation query
7. Use Solr in Java, historical version (after 7.0.0, 5.0.0~6.6.6, before 4.10.4)
8. Traditional Spring integration with Solr
9. Spring Boot integrates Solr
Solr Admin UI operation (XML, JSON add|modify|delete|query index)
- Table of contents
- Solr Admin UI operations (XML, JSON add|modify|delete|query index)
-
- Solr Admin UI overview
-
- display panel
- Login panel (requires setup)
-
- 1. Open /server/etc in the Solr installation root directory
- 2. Open the server/contexts/solr-jetty-context.xml file in the solr root directory
- 3. Open the /server/solr-webapp/webapp/WEB-INF/web.xml file in the solr root directory
- 4. Test login
- get help
- Admin UI operation index
-
- Add/modify index
-
- 1.xml
- 2. JSON
- delete index
-
- 1. XML
- Query index (common)
-
- query parameters
-
- 1.qt (query type)
- 2.q (query)
- 3.fq (filter query)
- 4.sort
- 5. start, rows
- 6. fl (field list)
- 7. df (default field)
- 8.Raw Query Parameters (raw query parameters)
- 9.wt (writer type)
- Solr search operators
- group
-
- Grouping (Field Facet)
- Grouping (Date Facet)
Solr Admin UI operation (XML, JSON add|modify|delete|query index)
Solr Admin UI Overview
Solr has a web interface that makes it easy for Solr administrators and programmers to view Solr configuration details, run queries, and analyze document fields in order to fine-tune Solr configuration and access online documentation and other help
Display panel
Access URL: http://localhost:8983/solr/, http://hostname:8983/solr/
The main dashboard is displayed, which is divided into two sections
For system-level information and configuration, and provides access to Logging, Collection/Core Administration, and Java Properties, etc.
At the end of that information is at least one dropdown listing the Solr cores configured for this instance. On SolrCloud nodes, an additional dropdown displays all collections in this cluster. Clicking on a collection or core name will display a secondary menu of information for the specified collection or core, such as Schema Browser, Config Files, Plugins & Statistics, and the ability to perform queries on indexed data.
The center of the screen displays the details of the selected option. This may include sub-navigation of options or a textual or graphical representation of the requested data
Behind the scenes, the Solr Admin UI reuses the same HTTP API available to all clients to access Solr-related data to drive the external interface
Login panel (requires setup)
If authentication is enabled, Solr will display a login screen to unauthenticated users before allowing them further access to the Admin UI
The login screen currently only works with basic auth
1. Open /server/etc in the Solr installation root directory
Create a new verify.properties configuration file (with any name) in this directory and add content.
Format: Username: Password, Permissions
#username password permissions user: pass,admin # Configurable multi-user user: pass,admin user1: pass,admin user3: pass, admin
2. Open the server/contexts/solr-jetty-context.xml file in the solr root directory
Add the configuration to get the user file in the file
<!-- Add configuration authorization authentication: add configuration to obtain user files in the file configure --> <Get name="securityHandler"> <Set name="loginService"> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">verify-name</Set> <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/verify.properties</Set> </New> </Set> </Get>
3. Open the /server/solr-webapp/webapp/WEB-INF/web.xml file in the solr root directory
Find the configuration of
Reconfigure a
<!--Reconfigure security-resource-collection (deleting the previous security-constraint will invalidate the login configuration) --> <security-constraint> <web-resource-collection> <web-resource-name>Solr</web-resource-name> <url-pattern>/</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>verify-name</realm-name> </login-config>
4. Test login
Solr has added username and password access conditions, and there is no place to set username and password in the parameters, so what should I do?
Spring Boot connects by adding a username and password to the solr address
spring: data: solr: # full text search host: http://user:[email protected]:8983/solr
Get help
At the bottom of every screen in the admin interface is a set of links for more help configuring and using Solr
These icons include the following links
Link | Description |
---|---|
Documentation | Navigate to the Apache Solr documentation hosted at https://lucene.apache.org/solr/ |
Issue Tracker | Navigates to the Apache Solr project’s JIRA issue tracking server The server is at https://issues.apache.org/jira/browse/SOLR |
IRC channel | Navigate to Solr’s IRC Live Chat Room: http://webchat.freenode.net/?channels=#solr |
Community Forum | Navigate to Apache Wiki page with more information on ways to get involved with Solr user community mailing lists: https://cwiki.apache.org/confluence/display/solr/UsingMailingLists |
Solr Query Syntax | Navigate to the “Query Syntax and Parsing” section of this reference guide |
Admin UI operation index
Prerequisite: configure managed.schema
Configured in the created core instance. Similar to database fields, configure as needed, try to have a prefix to avoid duplication
Add/modify index
After entering solr admin, click Documents, select Documentation Type as xml/json, and enter the document to be indexed in the Document(s) input box. Click Submit Document to add content to solr and build an index
parameter explanation
parameter | description |
---|---|
Overwrite | Whether to overwrite existing indexes. The default is true |
Commit Within | The unit is milliseconds. After the content is submitted, solr will update the index within the specified time. This function is for big data When submitting a large amount of content, some parts of the content do not have high real-time requirements, and the submission time can be delayed as needed |
If there is no index, it will be added, and if there is, it will be updated (according to
1.xml
<add> <doc> <field name="sid">157</field> <field name="sname" update="set">caomemgde</field> <field name="saddress" update="add">xuchang</field> </doc> </add>
Whether the index is added successfully, you can observe the statistics in the Overview to check whether the number of Num docs has increased
Example of multiple values for the same field
<add> <doc> <field name="employeeId">05991</field> <field name="skills" update="set">Python</field> <field name="skills" update="set">Java</field> <field name="skills" update="set">Jython</field> </doc> </add>
2.JSON
Adding an index in json format is similar to xml, just select json in Document Type
{"sid":158,"sname":"zhaozilong","saddress":"changbanpo"}
Delete index
1.XML
<delete> <query>sid:"156"</query> </delete> <commit/> <delete><id>156</id></delete> <commit/>
delete all indexes
<delete><query>*:*</query></delete> <commit/>
Query index (common)
The query result is returned in the response
Query parameters
parameter | description |
---|---|
qt(query type) | Specify the type to process the query request, generally do not need to specify, the default is standard. |
q | Keyword of the query, this parameter is the most important, for example, q=id:1, the default is q=: , |
fq(filter query) | filter query, providing an optional filter query. Return the query results that meet the fq conditions in the q query matching results, for example: q=id:1 & amp;fq=sort:[1 TO 5], find the keyword id is 1, and the sort is 1 to 5 |
sort | sorting method, for example, id desc means descending order according to “id” |
start | The first record of the returned result starts, generally used for pagination, the default starts at 0 |
rows | Specify how many records there are at most in the returned result, the default value is 10, cooperate with start to realize pagination |
fl | specifies which fields to return, separated by commas or spaces, note: fields are case-sensitive, for example, fl= id,title,sort |
df | The default query field is generally specified by default. |
wt(writer type) | Specify the output format, including xml, json, php, etc. |
indent | Whether the returned result is indented, the default is off, open: indent=true |
hl | Set the highlighted fields, a list of fields separated by spaces or commas. To enable the highlight function of a field, you must ensure that the field is stored in the schema. If this parameter is not given, then the default field will be highlighted. The standard handler will use the df parameter, and the dismax field will use the qf parameter. An asterisk can be used to conveniently highlight all fields. If wildcards are used, consider enabling the hl.requiredFieldMatch option.
hl.fl Field to highlight |
debugQuery | Set whether to display Debug information in the returned result |
spellcheck | spell check |
1.qt (query type)
Specify which type to process the query request, generally do not need to specify, the default is standard
2.q (query)
Query string, which must be specified, and the query results are scored according to the query words specified by this parameter
The query keyword, this parameter is the most important, for example, q=id:1, the default is q=:, similar to where 1=1 in SQL
3.fq (filter query)
Filter query, filter on the basis of q, does not affect scoring
Filter query, provide an optional filter query. Returns the query results that meet the fq conditions in the q query matching results, for example: q=id:1 & amp;fq=sort:[1 TO 5] & amp;fq=section:0, the search keyword id is 1 , and the sort is between 1 and 5, section=0. It can also be written as fq= + sort[1 TO 5] + section:0]
Performance considerations: the records under each fq will be cached separately. You can consider writing the fq conditions that are often together in the + way
4.sort
Sort according to the score of the query results or other specified characteristics. There are two kinds of sorting ascending (asc), descending (desc), case insensitive. Allows to sort by multiple fields, separated by commas.
NB: The sorted field must be an indexed field, and the type corresponding to the field cannot be multiValued
Sorting method, for example, id desc means descending order according to “id”. id desc, price asc First sort by id in descending order, then in ascending order by price. sum(x_f, y_f) desc descending order by sum of x_f and y_f fields
5.start,rows
Which record to start querying and how many records to query
Paging parameters, similar to the functions of start and limite. If you don’t lose anything, the default values are start=0, limit=10
6.fl (field list)
Define the field of the returned record
Specify which fields to return, separated by commas or spaces, note: fields are case-sensitive, for example, fl= id,title,sort or fl=id title sort or fl=id title,sort or (supported in versions after 4.0) fl= id &fl=title&fl=sort. Supports wildcards such as fl=tag* to return all fields starting with tag. Supported methods such as fl=sum(x,y), all supported methods and corresponding version numbers can be found in the link
7.df (default field)
Fields to look up by default. solr6.3.0 default df=text
8.Raw Query Parameters
9.wt (writer type)
Specifies the format of the returned data. The default is json
Specify the output format, including xml, json, php, etc.
Solr search operators
Symbol | Meaning |
---|---|
: | Specify the field to check the specified value, such as return all values |
? | Indicates a single wildcard of any character |
* | Indicates a wildcard of multiple arbitrary characters (* or? symbols cannot be used at the beginning of the retrieved item) |
~ | means fuzzy search, such as searching for items whose spelling is similar to “roam” is written like this: roam will find words such as foam and roams; roam0.8, the search returns words with a similarity above 0.8 Record |
+ | Existence operator, requires the item after the symbol “+” must exist in the corresponding field of the document |
() | Used to form a subquery |
[] | Include range retrieval, such as retrieval Records in a certain time period, including the beginning and the end, date:[202301 TO 202309] |
{} | does not include range retrieval, such as searching for records in a certain time period , not including the beginning and end date:{202301 TO 202309} |
Group
Group (Field Facet)
The facet parameter field must be indexed, facet=on or facet=true
parameter | description |
---|---|
facet.field | Grouped field |
facet.prefix | Indicates Facet field prefix |
facet.limit | Facet field returns the number of items |
facet.offict | The number of starting items, offset, it cooperates with facet.limit Use can achieve the effect of pagination |
facet.mincount | Facet field minimum count, the default is 0 |
facet.missing | If it is on or true, then the records whose Facet field value is null will be counted |
facet.sort | indicates the order in which the Facet field values are returned. The format is true (count) or false (index, lex), true (count) means sorting from large to small according to the count value, false (index, lex) means sorting by field The natural order (order of letters, numbers) of values to arrange. By default it is true(count) |
Group (Date Facet)
Facet the field of date type, Solr provides a more convenient query statistics method for the date field. Note that the field type of Date Facet must be DateField (or its subtype). It should be noted that when using Date Facet, the field Name, start time, end time, time interval these 4 parameters must be provided.
parameter | description |
---|---|
facet.date | This parameter indicates the name of the field that needs to be Date Facet. Like facet.field, this parameter can be set multiple times, indicating that Date Facet is performed on multiple fields |
facet .date.start | Starting time, the general format of the time is “2015-12-31T23:59:59Z”, and you can also use “NOW”, “YEAR”, “MONTH” and so on, |
facet.date.end end time | |
facet.date.gap | Time interval, if start is 2015-1-1, end is 2016-1-1, gap is set to “+ 1MONTH” means the interval is 1 month, then this time will be divided into 12 intervals |
facet.date.hardend | Indicates that when the gap iterates to end, there is still a part of the remaining time period, whether to continue to the next interval. The value can be true |