elasticsearch 弹性搜索过滤问题,elasticsearch,elasticsearch" /> elasticsearch 弹性搜索过滤问题,elasticsearch,elasticsearch" />

elasticsearch 弹性搜索过滤问题

elasticsearch 弹性搜索过滤问题,elasticsearch,elasticsearch,我在弹性搜索中过滤时遇到问题。我想筛选订单行的索引。与此sql查询类似: 从orderrow中选择*项,其中项目\u code='7X BogusItem' 以下是我的elasticsearch查询: GET /myindex/orderrow/_search { "query": { "constant_score": { "filter": { "term": { "item_co

我在弹性搜索中过滤时遇到问题。我想筛选订单行的索引。与此sql查询类似:

从orderrow中选择*项,其中项目\u code='7X BogusItem'

以下是我的elasticsearch查询:

GET /myindex/orderrow/_search
{
    "query": {
        "constant_score": {
           "filter": {
               "term": {
                  "item_code": "7X-BogusItem"
               }
           }
        }
    }
}
我没有得到任何结果。但当我运行此查询时:

GET /myindex/orderrow/_search
{
    "query": {
        "query_string": {
            "query": "7X-BogusItem"
        }
    }
}
我得到了正确的结果。我做错了什么?

您可以尝试:

GET /myindex/orderrow/_search
{
    "query": {
        "constant_score": {
           "filter": {
               "query": {
                  "query_string": {
                      "query": "7X-BogusItem"
                   }
               }
           }
        }
    }
}
问题是,查询\字符串查询是分析的,而术语查询不是。可能您的数据
7X BogusItem
在索引到
7X
BogusItem
等术语的过程中被默认analyzer转换。当您尝试使用term
7X BogusItem
执行查询时,它将不起作用,因为您没有term
7X BogusItem
——您只有terms
7X
BogusItem
。但是,执行query_string会将您的查询
7X BogusItem
转换为引擎盖下的术语
7X
BogusItem
,它会找到您想要的内容

如果您不希望analyzer转换文本
7X BogusItem
,可以将字段
项\u code
的映射选项更改为
“索引”:“未分析”

您可以检查分析后数据的外观:

curl -XGET "localhost:9200/_analyze?analyzer=standard&pretty" -d '7X-BogusItem'
{
  "tokens" : [ {
    "token" : "7x",
    "start_offset" : 0,
    "end_offset" : 2,
    "type" : "<ALPHANUM>",
    "position" : 1
  }, {
    "token" : "bogusitem",
    "start_offset" : 3,
    "end_offset" : 12,
    "type" : "<ALPHANUM>",
    "position" : 2
  } ]
}
curl-XGET“localhost:9200/_analyze?analyzer=standard&pretty”-d'7X BogusItem'
{
“代币”:[{
“令牌”:“7x”,
“起始偏移量”:0,
“端部偏移”:2,
“类型”:“,
“职位”:1
}, {
“令牌”:“bogusitem”,
“起始偏移量”:3,
“端部偏移”:12,
“类型”:“,
“职位”:2
} ]
}
因此,对于文本
7X BogusItem
我们在索引项
7X
BogusItem
中使用了以下内容:

GET /myindex/orderrow/_search
{
    "query": {
        "constant_score": {
           "filter": {
               "query": {
                  "query_string": {
                      "query": "7X-BogusItem"
                   }
               }
           }
        }
    }
}
问题是,查询\字符串查询是分析的,而术语查询不是。可能您的数据
7X BogusItem
在索引到
7X
BogusItem
等术语的过程中被默认analyzer转换。当您尝试使用term
7X BogusItem
执行查询时,它将不起作用,因为您没有term
7X BogusItem
——您只有terms
7X
BogusItem
。但是,执行query_string会将您的查询
7X BogusItem
转换为引擎盖下的术语
7X
BogusItem
,它会找到您想要的内容

如果您不希望analyzer转换文本
7X BogusItem
,可以将字段
项\u code
的映射选项更改为
“索引”:“未分析”

您可以检查分析后数据的外观:

curl -XGET "localhost:9200/_analyze?analyzer=standard&pretty" -d '7X-BogusItem'
{
  "tokens" : [ {
    "token" : "7x",
    "start_offset" : 0,
    "end_offset" : 2,
    "type" : "<ALPHANUM>",
    "position" : 1
  }, {
    "token" : "bogusitem",
    "start_offset" : 3,
    "end_offset" : 12,
    "type" : "<ALPHANUM>",
    "position" : 2
  } ]
}
curl-XGET“localhost:9200/_analyze?analyzer=standard&pretty”-d'7X BogusItem'
{
“代币”:[{
“令牌”:“7x”,
“起始偏移量”:0,
“端部偏移”:2,
“类型”:“,
“职位”:1
}, {
“令牌”:“bogusitem”,
“起始偏移量”:3,
“端部偏移”:12,
“类型”:“,
“职位”:2
} ]
}
因此,对于文本
7X BogusItem
我们在索引项
7X
BogusItem
中使用了以下内容:

GET /myindex/orderrow/_search
{
    "query": {
        "constant_score": {
           "filter": {
               "query": {
                  "query_string": {
                      "query": "7X-BogusItem"
                   }
               }
           }
        }
    }
}
问题是,查询\字符串查询是分析的,而术语查询不是。可能您的数据
7X BogusItem
在索引到
7X
BogusItem
等术语的过程中被默认analyzer转换。当您尝试使用term
7X BogusItem
执行查询时,它将不起作用,因为您没有term
7X BogusItem
——您只有terms
7X
BogusItem
。但是,执行query_string会将您的查询
7X BogusItem
转换为引擎盖下的术语
7X
BogusItem
,它会找到您想要的内容

如果您不希望analyzer转换文本
7X BogusItem
,可以将字段
项\u code
的映射选项更改为
“索引”:“未分析”

您可以检查分析后数据的外观:

curl -XGET "localhost:9200/_analyze?analyzer=standard&pretty" -d '7X-BogusItem'
{
  "tokens" : [ {
    "token" : "7x",
    "start_offset" : 0,
    "end_offset" : 2,
    "type" : "<ALPHANUM>",
    "position" : 1
  }, {
    "token" : "bogusitem",
    "start_offset" : 3,
    "end_offset" : 12,
    "type" : "<ALPHANUM>",
    "position" : 2
  } ]
}
curl-XGET“localhost:9200/_analyze?analyzer=standard&pretty”-d'7X BogusItem'
{
“代币”:[{
“令牌”:“7x”,
“起始偏移量”:0,
“端部偏移”:2,
“类型”:“,
“职位”:1
}, {
“令牌”:“bogusitem”,
“起始偏移量”:3,
“端部偏移”:12,
“类型”:“,
“职位”:2
} ]
}
因此,对于文本
7X BogusItem
我们在索引项
7X
BogusItem
中使用了以下内容:

GET /myindex/orderrow/_search
{
    "query": {
        "constant_score": {
           "filter": {
               "query": {
                  "query_string": {
                      "query": "7X-BogusItem"
                   }
               }
           }
        }
    }
}
问题是,查询\字符串查询是分析的,而术语查询不是。可能您的数据
7X BogusItem
在索引到
7X
BogusItem
等术语的过程中被默认analyzer转换。当您尝试使用term
7X BogusItem
执行查询时,它将不起作用,因为您没有term
7X BogusItem
——您只有terms
7X
BogusItem
。但是,执行query_string会将您的查询
7X BogusItem
转换为引擎盖下的术语
7X
BogusItem
,它会找到您想要的内容

如果您不希望analyzer转换文本
7X BogusItem
,可以将字段
项\u code
的映射选项更改为
“索引”:“未分析”

您可以检查分析后数据的外观:

curl -XGET "localhost:9200/_analyze?analyzer=standard&pretty" -d '7X-BogusItem'
{
  "tokens" : [ {
    "token" : "7x",
    "start_offset" : 0,
    "end_offset" : 2,
    "type" : "<ALPHANUM>",
    "position" : 1
  }, {
    "token" : "bogusitem",
    "start_offset" : 3,
    "end_offset" : 12,
    "type" : "<ALPHANUM>",
    "position" : 2
  } ]
}
curl-XGET“localhost:9200/_analyze?analyzer=standard&pretty”-d'7X BogusItem'
{
“代币”:[{
“令牌”:“7x”,
“起始偏移量”:0,
“端部偏移”:2,
“类型”:“,
“职位”:1
}, {
“令牌”:“bogusitem”,
“起始偏移量”:3,
“端部偏移”:12,
“类型”:“,
“职位”:2
} ]
}

因此,对于文本
7X BogusItem
我们有索引项
7X
BogusItem

,答案是描述您遇到的问题。如果希望保持能够搜索的行为,请添加一个不分析的multi_字段。是我