Elasticsearch:使用2个预先处理的数组进行邻近搜索

2024-04-25 23:55:30 发布

您现在位置:Python中文网/ 问答频道 /正文

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

例如,在两个人的价值观中,从preToke中找到married这个词。你知道吗

候选人=[u'PERSON',u'PERSON',u'O',u'O',u'O',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'was',u'born',u'as',u'Claudia',u'Alta',u'Taylor',u'and',u'married',u'Lyndon',u'B.',u'Johnson',u'in',u'1934',u'.]

这是我的地图

`{
  "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"
        }
      }
    }
    )`

Tags: textinindextypecorpusquerypersonoptions