如何在DSE搜索json查询中使用转义字符?

时间:2017-08-28 23:53:38

标签: solr cassandra datastax

我第一次使用DSE搜索,我有一个如下表格:

 CREATE TABLE keyspace1.table1 (
    id bigint,
    is_dir boolean,
    dir text,
    name text,
    created_date timestamp,
    size bigint,
    solr_query text,
    status text,
    PRIMARY KEY (id, is_dir, dir, name)
) WITH CLUSTERING ORDER BY (is_dir ASC, dir ASC, name ASC)



select id, is_dir, dir,name, created_date from keyspace1.table1 where solr_query= '{"fq":"is_dir:false", "q": "name:(abc and local.h) "}'  limit 10;

   id | is_dir | dir                          | name    | created_date
------------+--------+------------------------------+---------+---------------------------------
  205 |  False | /include/config/have         | local.h | 2017-08-25 02:54:54.000000+0000
  332 |  False |                            / |     abc | 2017-08-27 17:31:55.000000+0000

我在其上创建了solr core,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<schema name="autoSolrSchema" version="1.5">
  <types>
    <fieldType class="org.apache.solr.schema.TrieLongField" name="TrieLongField"/>
    <fieldType class="org.apache.solr.schema.StrField" name="StrField"/>
    <fieldType class="org.apache.solr.schema.BoolField" name="BoolField"/>
    <fieldType class="org.apache.solr.schema.TrieDateField" name="TrieDateField"/>
  </types>
  <fields>
    <field docValues="true" indexed="true" multiValued="false" name="id" stored="true" type="TrieLongField"/>
    <field docValues="true" indexed="true" multiValued="false" name="name" stored="true" type="StrField"/>
    <field indexed="true" multiValued="false" name="is_dir" stored="true" type="BoolField"/>
    <field indexed="true" multiValued="false" name="dir" stored="true" type="StrField"/>
    <field docValues="true" indexed="true" multiValued="false" name="created_date" stored="true" type="TrieDateField"/>
  </fields>
  <uniqueKey>(id,is_dir,dir,name)</uniqueKey>
</schema>

我想用选择数据编写q查询,其中is_dir = false和name =&#39; abc&#39;和dir =&#39; /&#39;。

到目前为止,我可以为前两个过滤器选择数据,如下所示:

select id, is_dir, dir,name, created_date from keyspace1.table1 where solr_query= '{"fq":"is_dir:false", "q": "name:(abc)"}'  limit 10;

  id | is_dir | dir | name | created_date
-----+--------+-----+------+---------------------------------
 332 |  False |   / |  abc | 2017-08-27 17:31:55.000000+0000

但是当我尝试添加dir =&#39; /&#39;时,我面临语法错误:

select id, is_dir, dir,name, created_date from keyspace1.table1 where solr_query= '{"fq":"is_dir:false", "q": "name:(abc and local.h) && dir:/"}'  limit 10;

InvalidRequest: Error from server: code=2200 [Invalid query] message="org.apache.solr.search.SyntaxError: Cannot parse 'name:(abc and local.h) && dir:/': Lexical error at line 1, column 32.  Encountered: <EOF> after : """

请告知。

感谢。

1 个答案:

答案 0 :(得分:0)

逃离\

示例:

select id, is_dir, dir,name, created_date from keyspace1.table1 where solr_query= '{"fq":"is_dir:false", "q": "name:(abc and local.h) && dir:\/"}'  limit 10;