Search Query Help

I inserted records with below commands:

    POST dnmindex1/doc/
    {
        "matches": [
            {
                "XURI": "xcp:4.1:a:abcv12:abcp12:6.0:*:*:*:*:*:*:*"           
            },
            {
                "XURI": "xcp:4.1:a:abcv1:abcp1:6.0:beta1:*:*:*:*:*:*",         
            },
            {
                "XURI": "xcp:4.1:a:abcv:abcp:6.0:beta2:*:*:*:*:*:*",          
            }
        ]
    }


    POST dnmindex1/doc/
    {
        "matches": [
            {
                "XURI": "xcp:4.1:a:abcv-abc12:abcp-abc12:6.0:*:*:*:*:*:*:*"          
            },
            {
                "XURI": "xcp:4.1:a:abcv-abc1:abcp-abc1:6.0:beta1:*:*:*:*:*:*",          
            },
            {
                "XURI": "xcp:4.1:a:abcv-abc:abcp-abc:6.0:beta2:*:*:*:*:*:*",          
            }
        ]
    }


    POST dnmindex1/doc/
    {
        "matches": [
            {
                "XURI": "xcp:4.1:a:bgbgbv:bgbgbp:6.0:*:*:*:*:*:*:*"           
            },
            {
                "XURI": "xcp:4.1:a:bgbgbv-abc1:bgbgbp-abc1:6.0:beta1:*:*:*:*:*:*",           
            },
            {
                "XURI": "xcp:4.1:a:bgbgbv-abc:bgbgbp-abc:6.0:beta2:*:*:*:*:*:*",          
            }
        ]
    }

Now I want to get record which has :abcv-abc12:abcp-abc12:

I used below query but got error.

    GET dnmindex1/_search
    {
    "query": {
    	"bool": {
    	"must": [
    		{
    			"query_string": {
    			        "default_field": "matches.XURI",
    			        "query": ":abcv-abc12:abcp-abc12:"
    		}
    		}
    		]
    	}
    }
    }

What is wrong with my search query? What query should I use to get the record I want?

The problem is that the query string query tries to parse the content to see if you want to search in specific fields. i.e.: fielda:foo fieldb:bar which would indicate that you want to search for foo value in field fielda or bar in field fieldb.

As you are using also this ":" character, it make fails the request.

Instead try:

GET dnmindex1/_search
{
  "query": {
    "match": {
      "matches.XURI": ":abcv-abc12:abcp-abc12:"
    }
  }
}

Or

GET dnmindex1/_search
{
  "query": {
    "simple_query_string": {
        "fields": ["matches.XURI"],
        "query": ":abcv-abc12:abcp-abc12:"
    }
  }
}

Both are worked. Thanks.

But if I search xcp:4.1:a:abcv-abc12:abcp-abc12: they don't work properly. I guess because of the dot (4.1) . What can I do in this case?

You need to understand how analyzers are working behind the scene. Try the _analyze API to see how your text is actually indexed at index time and search time. See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html

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