Type为text 的情况下,设置"index"为 "not_analyzed"好像不起作用

"properties": {
  "columns": {
    "properties": {
      "id": {
        "type": "keyword",
        "index": "not_analyzed"
      },
      "name": {
        "type": "keyword",
        "index": "not_analyzed"
      },
      "siteId": {
        "type": "keyword",
        "index": "not_analyzed"
      }
    }
  },
  "text": {
    "type": "text",
    "store": "false",
    "analyzer": "hanlp",
    "fields": {
      "keyword": {
        "type": "text",
        "index": "not_analyzed",
        "fielddata": "true"
      }
    }
  }
}

为了实现模糊查询,我使用以下方式进行查询:

GET/book_page/book_page/_search
{
      "from": 0,
      "size": 10,
      "query": {
        "bool": {
          "must": [
            {
              "script": {
                "script": {
                  "inline": "doc['text_nlp_sore.keyword'].value!=null&&doc['text_nlp_sore.keyword'].value.indexOf(params.a)!=-1",
                  "lang": "painless",
                  "params": {
                    "a": "中文"
                  }
                }
              }
            }
          ]
        }
      },
      "sort": [
        {
          "_script": {
            "script": {
              "inline": "String myText=doc['text_nlp_sore.keyword'].value;if(myText!=null){int count=0;int index=-1;while((index=myText.indexOf(params.a))!=-1){count++;myText=myText.substring(index+params.a.length())}return Math.log(count);}else{return 0;}",
              "lang": "painless",
              "params": {
                "a": "中文"
              }
            },
            "type": "string",
            "order": "desc"
          }
        },
        {
          "bookDate_date_sore": {
            "order": "desc"
          }
        }
      ],
      "highlight": {
        "fields": {
          
        }
      }
    }

但是什么搜索不出来,我怀疑doc['text_nlp_sore.keyword'].value 是分词吗?但我明确地设置了 "index": "not_analyzed"。所以我想知道我在这一部分是否犯了错误?请告诉我。谢谢你

如果是 keyword 类型,就不用再设置 index为 not_analyzed 参数,默认就是整体。
另外 index 的参数也变了,只有 true 和 false。

好的,谢谢。

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.