# Type为text 的情况下，设置"index"为 "not\_analyzed"好像不起作用

**URL:** <https://discuss.elastic.co/t/type-text-index-not-analyzed/135285>\
**Category:** 中文提问与讨论\
**Created:** [June 11, 2018, 4:00am UTC](https://discuss.elastic.co/t/type-text-index-not-analyzed/135285 "2018-06-11T04:00:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [June 11, 2018, 4:00am UTC](https://discuss.elastic.co/t/type-text-index-not-analyzed/135285/1 "2018-06-11T04:00:56Z")

</div>

```
"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"。所以我想知道我在这一部分是否犯了错误？请告诉我。谢谢你

---

<div class="post-metadata">

**Author:** ![medcl.net](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/medcl.net/32/4414_2.png) [@medcl.net](https://discuss.elastic.co/u/medcl.net)\
**Post date:** [June 13, 2018, 1:52am UTC](https://discuss.elastic.co/t/type-text-index-not-analyzed/135285/2 "2018-06-13T01:52:28Z")

</div>

> [@hubiao](#):
>
> "type": "keyword", "index": "not\_analyzed"

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

---

<div class="post-metadata">

**Author:** ![hubiao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hubiao/32/26178_2.png) [@hubiao](https://discuss.elastic.co/u/hubiao)\
**Post date:** [June 28, 2018, 9:06am UTC](https://discuss.elastic.co/t/type-text-index-not-analyzed/135285/3 "2018-06-28T09:06:27Z")

</div>

好的，谢谢。

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 26, 2018, 9:06am UTC](https://discuss.elastic.co/t/type-text-index-not-analyzed/135285/4 "2018-07-26T09:06:29Z")

</div>

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