Elasticsearch:使用2个预标记化数组进行邻近搜索

时间:2017-08-07 00:24:57

标签: python elasticsearch lucene

我希望能够在两个存储为单独字段的独立数组中进行搜索。

例如,要在候选者中的两个PERSON值之间找到从preToke结婚的单词。

候选人= [u'PERSON',u'PERSON',u'PERSON',u'O',u'O',u'O',u'PERSON',u'PERSON',u'PERSON' ,u'O',u'O',u'PERSON',u'PERSON',u'PERSON',u'O',u'DATE',u'O']

pretoke = [u'Lady',u'Bird',u'Johnson',你是',u'born',u'as',u'Claudia',u'Alta',u'Taylor' ,你和','结婚','你'','u'B。','u'Johnson','u'',u'1934',你'。']

这是我的映射

`{
  "corpus" : {
    "mappings" : {
      "articles" : {
        "properties" : {
          "candidates" : {
            "type" : "text",
            "index_options" : "offsets"
          },
          "lineNum" : {
            "type" : "integer"
          },
          "preToke" : {
            "type" : "text",
            "index_options" : "offsets"
          },
          "sentence" : {
            "type" : "text"
          }
        }
      }
    }
  }
}`

这是我尝试的查询,但它返回0结果。

`searchResult = es.search(
    index="corpus",
    size=20,
    body={
      "query": {
        "span_near": {
          "clauses": [
            {
              "span_term": {
                "candidates": "person"
              }
            },
            {
              "field_masking_span": {
                "query": {
                  "span_term": {
                    "preToke": "married"
                  }
                },
                "field": "candidates"
              }
            },
            {
              "span_term": {
                "candidates": "person"
              }
            },
          ],
          "slop": 20,
          "in_order": "true"
        }
      }
    }
    )`

0 个答案:

没有答案